Jump to content

Recommended Posts

It's a login script, after the user logs in I want the login script to redirect the user back to the page the login request came from.

 

Say you're at page x.php and click the login button that forwards username and password to the login.php page.  After the user is logged in and the session is created I want the user directed back to the page the request was made from.  So the user should end up back at x.php, but logged in.  The login.php file is just a "middleman" page that sets some database record changes and creates the session.

header("Location: {$_SERVER['PHP_SELF']}");

 

You were using single quotes, $ in single quotes is taken literally. Try the above.

 

Its never a good idea to rely on PHP_SELF anyway even if you do get it to work.  Why not save the address as a session variable or GET/POST variable then extract it to use for the header() function.

How is using php_self bad? It cannot be modified outside since it is a server variable. I fail to see your reasoning, please elaborate for us all, thanks!

Mad Mick,

 

If this is my code:

<form action='login.php?try=true' method='post'>
<lable for='username'>Username: </lable><input name='username' type='text' class='text_boxes' maxlength='20'/><br>
<label for='password'>Password: </label><input name='password' type='password' class='text_boxes' maxlength='20'/><br>
<input name='login' type='image' src='images/login.gif' /><br>
<span class='medium_text'><a href='register.php'>Register</a> | <a href='passrec.php'>Forget your password?</a></span>
</form>

 

How can I get the current page into a variable to pass to the login.php page?  Maybe make a hidden form item and call it in the login.php page like the username and password items?

Mad Mick,

 

If this is my code:

<form action='login.php?try=true' method='post'>
<lable for='username'>Username: </lable><input name='username' type='text' class='text_boxes' maxlength='20'/><br>
<label for='password'>Password: </label><input name='password' type='password' class='text_boxes' maxlength='20'/><br>
<input name='login' type='image' src='images/login.gif' /><br>
<span class='medium_text'><a href='register.php'>Register</a> | <a href='passrec.php'>Forget your password?</a></span>
</form>

 

How can I get the current page into a variable to pass to the login.php page?  Maybe make a hidden form item and call it in the login.php page like the username and password items?

 

header("Location: {$_SERVER['PHP_SELF']}");

 

Try that and see if that works for ya.

 

Ah sorry - I'm thinking of PHP_REFERRER.  I'll get my coat...

 

Np, I just wanted to make sure I did not miss something =)

The problem is the header code is in my login.php or logout.php pages.  If I use $_SERVER['PHP_SELF'] there, it'll be login.php or logout.php not the previous page.  I tried making a hidden input in the form the login button is in that has a value us $_SERVER['PHP_SELF'] and it passes the variable to the login.php page, but won't load that page.

For starters does it really need to be so flexible?  Can you not just hard code the page you want to go back to in the header() function?

 

If not then the method you are using is fine.  If the page does not load then echo what the header() function is supposed to be acting upon so you can see where it thinks it should redirect.  I'm sure it can only be typos etc...

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.