Jump to content


Photo

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


  • Please log in to reply
7 replies to this topic

#1 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 18 August 2006 - 07:14 PM

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...

<a href="?pg=login&redir=http://my.server.domain/?pg=page_you_are_on">login</a>

then, on the login page i captured $_GET['redir'] and created a hidden form value...

<input type="hidden" name="redir" value="http://my.server.domain/?pg=page_you_are_on"/>

then, on form submission i do the following...


if($_POST['redir']) {
   header('Location: '.$_POST['redir']);
} else {
   header('Location: http://my.server.domain/?pg=default_page');
} exit();


no luck! i should note i've tried urlencode() on the $_GET and that's not helping either :(  any suggestions??

#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 18 August 2006 - 07:39 PM

And what happens when you try this?

#3 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 18 August 2006 - 07:43 PM

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

#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 18 August 2006 - 07:46 PM

try:
<?php
if(!empty($_POST['redir'])) {
   header('Location: '.$_POST['redir']);
} else {
   header('Location: http://my.server.domain/?pg=default_page');
} exit();
?>


#5 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 18 August 2006 - 07:54 PM

try
<a href="?pg=login&redir=<? echo rawurlencode('http://my.server.domain/?pg=page_you_are_on') ?>">login</a>

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#6 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 18 August 2006 - 08:02 PM

try:

<?php
if(!empty($_POST['redir'])) {
   header('Location: '.$_POST['redir']);
} else {
   header('Location: http://my.server.domain/?pg=default_page');
} exit();
?>


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.

#7 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 18 August 2006 - 08:03 PM

try

<a href="?pg=login&redir=<? echo rawurlencode('http://my.server.domain/?pg=page_you_are_on') ?>">login</a>


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?

#8 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 18 August 2006 - 10:32 PM

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
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users