October 10th, 2013, 05:06 AM
Help with special character PHP
I want my url to look like
and this is my code:
echo'<form action="" method="get">
<button id="previouspage" name="'.$encodedURL.'" type="submit" value="'.$page.'">Previous Page</button>
<button id="nextpage" name="currentPage" type="submit" value="'.$pageN.'">Next Page</button>
echo "Inside Div";
when i click previouspage button , my url becomes locl.cms.com/upload/season.php?sid%253D20%2526currentPage=1
October 10th, 2013, 07:37 AM
there are two problems.
First of all, you misunderstand the purpose of urlencode(). What this function does is escape characters so that they can be used as data in a URL. Some characters like "?" have a special meaning in URL, so if you want to use them literally, they need to be escaped.
When you run your whole URL through urlencode(), then you break all meaningful characters, because they're all escaped. You need to escape the data like $sid. And then you need to HTML-escape the URL (for security reasons and to avoid the infamous ampersand issue).
The next issue is that for some reason you apply urlencode() twice. This way you end up with a completely garbled URL.
You need something like this:
$foo = 'speci&l';
$bar = 'speci%l';
$url = 'http://example.com?foo='.urlencode($foo).'&bar='.urlencode($bar);
$escaped_url = htmlentities($url, ENT_QUOTES, 'UTF-8');
October 10th, 2013, 08:23 AM