...

View Full Version : Resolved Encoding a URL and passing it as a variable



wldrumstcs
10-12-2009, 08:57 PM
This is driving me crazy, and I know it's an easy one. I need to encode a URL such that ampersands become "amp;" etc. This then needs to get passed from one page to another through the URL. Basically, if a user tries to access a page while not being logged in, the encoded URL of the page he tried to access is sent as the variable "redirect" through the URL to the login page.

I tried using


header("Location: login.php?a=logout&redirect=http://".urlencode($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
exit();


But this doesn't work for a URL like "www.mysite.com/profile.php?view=signature&action=change". Nothing gets passed for some reason.

oesxyl
10-12-2009, 09:40 PM
This is driving me crazy, and I know it's an easy one. I need to encode a URL such that ampersands become "amp;" etc. This then needs to get passed from one page to another through the URL. Basically, if a user tries to access a page while not being logged in, the encoded URL of the page he tried to access is sent as the variable "redirect" through the URL to the login page.

I tried using


header("Location: login.php?a=logout&redirect=http://".urlencode($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
exit();


But this doesn't work for a URL like "www.mysite.com/profile.php?view=signature&action=change". Nothing gets passed for some reason.
htmlspecialchars can change & to entity &
http://www.php.net/manual/en/function.htmlspecialchars.php

urlencode it's result.

best regards

wldrumstcs
10-12-2009, 09:56 PM
Worked like a charm. Thanks!

oesxyl
10-12-2009, 09:58 PM
Worked like a charm. Thanks!
you are welcome, :)

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum