bcamp1973 Posted August 18, 2006 Share Posted August 18, 2006 I'm trying to make it so that wherever a user is on the site, if they choose the login link, it takes them to a login page, then redirects them back to the previous page they were on on submission of the form. I can't quite get it to work. Here's what i'm doing...I captured the current $_GET string and used it to build the login link...[code]<a href="?pg=login&redir=http://my.server.domain/?pg=page_you_are_on">login</a>[/code]then, on the login page i captured $_GET['redir'] and created a hidden form value...[code]<input type="hidden" name="redir" value="http://my.server.domain/?pg=page_you_are_on"/>[/code]then, on form submission i do the following...[code]if($_POST['redir']) { header('Location: '.$_POST['redir']);} else { header('Location: http://my.server.domain/?pg=default_page');} exit();[/code]no luck! i should note i've tried urlencode() on the $_GET and that's not helping either :( any suggestions?? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 18, 2006 Share Posted August 18, 2006 And what happens when you try this? Quote Link to comment Share on other sites More sharing options...
bcamp1973 Posted August 18, 2006 Author Share Posted August 18, 2006 it goes straight to the default page and acts as though the redirect variable isn't set. it is however, when i check the html code the hidden input is populated with the correct string Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 18, 2006 Share Posted August 18, 2006 try:[code]<?phpif(!empty($_POST['redir'])) { header('Location: '.$_POST['redir']);} else { header('Location: http://my.server.domain/?pg=default_page');} exit();?>[/code] Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 18, 2006 Share Posted August 18, 2006 try[code]<a href="?pg=login&redir=<? echo rawurlencode('http://my.server.domain/?pg=page_you_are_on') ?>">login</a>[/code] Quote Link to comment Share on other sites More sharing options...
bcamp1973 Posted August 18, 2006 Author Share Posted August 18, 2006 [quote author=GingerRobot link=topic=104792.msg418167#msg418167 date=1155930360]try:[code]<?phpif(!empty($_POST['redir'])) { header('Location: '.$_POST['redir']);} else { header('Location: http://my.server.domain/?pg=default_page');} exit();?>[/code][/quote]ok, the issue was a stupid mistake on my part so it works, however you got me thinking in the right direction and i tested to see that $_POST['redir'] was not being passed. thanks for leading me in the right direction. Quote Link to comment Share on other sites More sharing options...
bcamp1973 Posted August 18, 2006 Author Share Posted August 18, 2006 [quote author=ryanlwh link=topic=104792.msg418176#msg418176 date=1155930863]try[code]<a href="?pg=login&redir=<? echo rawurlencode('http://my.server.domain/?pg=page_you_are_on') ?>">login</a>[/code][/quote]i'm a bit of a novice and the php manual only skims over the details...can you enlighten me as to the benefits of using urlencode() or rawurlencode()? I'm not clear on what it really does to help? Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 18, 2006 Share Posted August 18, 2006 sometimes the browser will not give you the correct value of a GET variable if it contains url special characters (examples: "/" ,"&"). but if you use urlencode or rawurlencode, then these special chars will be changed into escape codes that the browser understands... sort of like the backslashes for browsers address bar Quote Link to comment 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.