note 45499 added to function.urlencode

From: Date: Thu, 09 Sep 2004 08:00:34 +0000
Subject: note 45499 added to function.urlencode
Groups: php.notes 
Request: Send a blank email to php-notes+get-76276@lists.php.net to get a copy of this message
If you want to pass a url with parameters as a value IN a url AND through a javascript function, such as... <a href="javascript:openWin('page.php?url=index.php?id=4&pg=2');"> ...pass the url value through the PHP urlencode() function twice, like this... <?php $url = "index.php?id=4&pg=2"; $url = urlencode(urlencode($url)); echo "<a href=\"javascript:openWin('page.php?url=$url');\">"; ?> On the page being opened by the javascript function (page.php), you only need to urldecode() once, because when javascript 'touches' the url that passes through it, it decodes the url once itself. So, just decode it once more in your PHP script to fully undo the double-encoding... <?php $url = urldecode($_GET['url']); ?> If you don't do this, you'll find that the result url value in the target script is missing all the var=values following the ? question mark... index.php?id=4 ---- Manual Page -- http://www.php.net/manual/en/function.urlencode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45499 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45499&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45499&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76276) next »