curseknight / phurl

Automatically exported from code.google.com/p/phurl
0 stars 0 forks source link

Suggestion #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Suggestion, instead of generating code that is sequential make it more
random so bots cant guess all of the urls

function generate_code($length)
{
    $_rand_src = array(
        array(50,57) //digits
        , array(97,107) //lowercase chars
        , array(109,110) //lowercase chars
        , array(112,122) //lowercase chars
        , array(65,75) //uppercase chars
        , array(77,78) //uppercase chars
        , array(80,90) //uppercase chars
    );
    srand ((double) microtime() * 1000000);
    $random_string = "";
    for($i=0;$i<$length;$i++){
        $i1=rand(0,sizeof($_rand_src)-1);
        $random_string .= chr(rand($_rand_src[$i1][0],$_rand_src[$i1][1]));
    }
    return $random_string;
}

Original issue reported on code.google.com by itspa...@gmail.com on 12 May 2010 at 3:47

GoogleCodeExporter commented 9 years ago
I tested this code on my local copy, and it made my 26 character URL into a 119
character one. It generated a huge string...

Original comment by feddemas...@gmail.com on 3 Jun 2010 at 1:41

GoogleCodeExporter commented 9 years ago
This was not to convert the URL to a code. It is the code to generate a random 
code to use as the small URL. The existing 
code goes sequential. Smallurl.com/1000,Smallurl.com/1001,Smallurl.com/1003 etc

this makes it /a631g /b8d5a etc etc  

Original comment by itspa...@gmail.com on 3 Jun 2010 at 2:34

GoogleCodeExporter commented 9 years ago
I know. All I did was replace the original generate_code() function with yours. 
I was
going to post an example now, but I can't seem to recreate the problem.

But I assure you that your code generated a string that was 119 chars long...

Original comment by feddemas...@gmail.com on 3 Jun 2010 at 3:48

GoogleCodeExporter commented 9 years ago
What number did u put into the function?

Original comment by itspa...@gmail.com on 3 Jun 2010 at 4:22

GoogleCodeExporter commented 9 years ago
Ah, I should've put some more time into it instead of copy pasting it... I 
didn't
change it, causing the $lenght to be the same as the number of urls converted. 
On my
local backup that's about 5 urls, while on my online version it is in the 
hundreds.
So the lenght was set to 100+

Those night-shifts are getting to me :P Sorry, your code seems fine. Thanx.

Original comment by feddemas...@gmail.com on 3 Jun 2010 at 4:41

GoogleCodeExporter commented 9 years ago
ya i was replying from my iphone on a bumpy road.

but its ment for the code that you would generate and give to the user, and 
store
this code and the matching long url.

this code makes it random, the length parameter determines the length of the 
code. it
excludes certain characters that look the same. (ex: zero, L, one)

the reason i came across this is because the existing code would generate them 
in
order, and i would rather it be more random so someone couldnt make an exact 
backup
of my database

Original comment by itspa...@gmail.com on 3 Jun 2010 at 10:57

GoogleCodeExporter commented 9 years ago

Original comment by hcblahb...@gmail.com on 3 Jul 2010 at 8:50

GoogleCodeExporter commented 9 years ago
I think this should be made an (config) option for added 'security' of URLs, or 
so that they can't be harvested/indexed.

Original comment by dcedr...@gmail.com on 3 Jul 2010 at 5:47

GoogleCodeExporter commented 9 years ago
We may add this as a new feature in phurl v3. However, in phurl v 2, we have 
decided to leave it as it is.
Thank you for your suggestion.

Original comment by julfo%ju...@gtempaccount.com on 7 Jul 2010 at 10:07