tallberg Posted February 25, 2009 Share Posted February 25, 2009 some reason i cant understand urlencode has no effect. For example: echo '<a href="unsubscribe.php?asdfmikyrhdg=', urlencode($userinput), '">a link</a>'; The encode $userinput is not encoded. Help Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/ Share on other sites More sharing options...
blintas Posted February 25, 2009 Share Posted February 25, 2009 do a print $userinput; and tell me what it says Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/#findComment-771085 Share on other sites More sharing options...
tallberg Posted February 25, 2009 Author Share Posted February 25, 2009 $userinput = 'jack'; print($userinput); // result: jack echo '<a href="hdsfsad.php?foo=', urlencode($userinput), '">a link</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/#findComment-771105 Share on other sites More sharing options...
JonnoTheDev Posted February 25, 2009 Share Posted February 25, 2009 Your syntax is bad echo '<a href="hdsfsad.php?foo=', urlencode($userinput), '">a link</a>'; Should be echo '<a href="hdsfsad.php?foo='.urlencode($userinput).'">a link</a>'; And secondly the encoded version of jack is still jack! Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/#findComment-771116 Share on other sites More sharing options...
tallberg Posted February 25, 2009 Author Share Posted February 25, 2009 Ok so with the correct syntax jack still remain jack when what i want is an encoded jack $userinput = 'jack'; print($userinput); echo '<a href="hdsfsad.php?foo='.urlencode($userinput).'">a link</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/#findComment-771122 Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 Do you understand what urlencode does? As neil stated, jack would be jack. urlencode basically takes a string that may have bad characters (space single quote double quote ampersand) and converts them to save characters to pass through the url world (space amounts to %20). Just so you know why the above is considered "working". An "encoded" jack. How do you want it encoded? Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/#findComment-771125 Share on other sites More sharing options...
JonnoTheDev Posted February 25, 2009 Share Posted February 25, 2009 Im not sure what you are expecting. urlencode() is for encoding non-alphanumeric characters only into their corresponding hex equivelent. i.e. $x = "text+1234 abc_99 &?"; $x = urlencode($x); then decode after passed through url $y = urldecode($_GET['x']); Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/#findComment-771129 Share on other sites More sharing options...
tallberg Posted February 25, 2009 Author Share Posted February 25, 2009 Ok it see. I got the wrong end of the stick. What im doing is making an unsubscribe function to go in newsletters. I don't want a hacker to find my unsubscribe page and unsubscribe a lot of predictable email addresses. Im sure you can see what the encode idea is about. Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/#findComment-771139 Share on other sites More sharing options...
JonnoTheDev Posted February 25, 2009 Share Posted February 25, 2009 Then dont use the email address to unsubscribe members. What you want is a unique lets say 25 character key against the users records in the database. This key is used to unsubscribe the member. i.e. unsubsc.php?key=h65$$3esc55ijgg222jbs76 etc Quote Link to comment https://forums.phpfreaks.com/topic/146871-urlencode/#findComment-771140 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.