spinman Posted January 7, 2008 Share Posted January 7, 2008 Hi, As a relative newbie, I am trying to create a link on one page to another page on my site using urlencode to encode the URL (together with a little javascript onclick code). The problem I have is that when I run the code using urlencode(), I get a 403 permission denied error. If I run the same thing without urlencode it works find. I tried this both on my locally installed wamp setup as well as on my hosted site. The code (which I have simplified as much as possible for this question) is: <?php //This is the "go_from.php" page // Run this and then click one of the buttons $url=urlencode("go_to.php?var=1"); $url1="go_to.php?var=1"; $text .= "<form method='get'> <div><input type='button' value='Select the Go To Page WITH encoded URL' onclick=\"javascript:window.location='$url';\"></div> <div><input type='button' value='Select the Go To Page WITHOUT encoded URL' onclick=\"javascript:window.location='$url1';\"></div> </form>"; echo $text; ?> ...and it is calling this page: <?php //this is the "go_to.php" page which is called by "go_from.php" echo "This is the go to page"; echo $_GET['var']; ?> Any ideas as to why the top button errors out? Thanks in advance, Dennis PS: Correction - I used GET (not POST) Quote Link to comment https://forums.phpfreaks.com/topic/84825-need-urlencode-help/ Share on other sites More sharing options...
btherl Posted January 7, 2008 Share Posted January 7, 2008 The "?" in a URL should not be url encoded. The parts to encode are the values of each get variable. In your case, you would encode the value "1" (which just encodes to itself). But if you wanted to set "var=&" for example, you would need to urlencode the "&" Quote Link to comment https://forums.phpfreaks.com/topic/84825-need-urlencode-help/#findComment-432477 Share on other sites More sharing options...
spinman Posted January 7, 2008 Author Share Posted January 7, 2008 Thanks for clearing that up for me! So if I understand you correctly, if I needed to build an encoded URL which passes multiple variables, I would do something like: <?php $url="go_to.php?var1=" . urlencode($var1) . "&var2=" . urlencode($var2) . "&var3=" . urlencode($var3); ?> This works fine, I was just hoping for an easier way to convert a url in one go, but thanks in any case! Dennis Quote Link to comment https://forums.phpfreaks.com/topic/84825-need-urlencode-help/#findComment-432504 Share on other sites More sharing options...
btherl Posted January 7, 2008 Share Posted January 7, 2008 Yep, that's basically it. I don't know of any simple way to do that encoding. About the &, you may not need that if you are setting the url using window.location. I'm not sure about that. The whole thing about when you need & kinda confuses me actually If it doesn't work, try it as just plain "&" Quote Link to comment https://forums.phpfreaks.com/topic/84825-need-urlencode-help/#findComment-432528 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.