Jump to content

redirect to original page on login...not working :(


bcamp1973

Recommended Posts

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??
Link to comment
Share on other sites

[quote author=GingerRobot link=topic=104792.msg418167#msg418167 date=1155930360]
try:
[code]
<?php
if(!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.
Link to comment
Share on other sites

[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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.