Connecting Tech Pros Worldwide Forums | Help | Site Map

login then back to the previous page

Newbie
 
Join Date: Nov 2008
Posts: 3
#1: Nov 2 '08
Hi I am a newbie, and I am having some troubles need someone to help me out. I am currently having a login page.

heres my login form
Expand|Select|Wrap|Line Numbers
  1. <form action="member.php?action=logindo" method="post" id="form_login" name="form_login" >
  2. <input type="text" name="txtloginname" id="txtloginname" tabindex="1"/>
  3. <input type="text" name="txtloginpwd" id="txtloginpwd" tabindex="1"/>
  4. <input name="save" id="save" value="submit">
  5. </form>
How do I write a php page so that if someone login then the page will back to the previous page automatically. (LIKE EBAY)

should I use <input="hidden" or ['_SERVER']['HTTP_REFERER']??

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,940
#2: Nov 2 '08

re: login then back to the previous page


Have a hidden input on your form that stores the url of the page the form is on (relative or full). Then use the header() function to redirect to the page.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,748
#3: Nov 3 '08

re: login then back to the previous page


You could also just use the $_SERVER['HTTP_REFERER'] variable in your "member.php" page.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Do your login stuff here...
  3.  
  4. header("Location: ". $_SERVER['HTTP_REFERER']);
  5. ?>
  6.  
Note that the HTTP_REFERER is supplied by the client, so this might be used to feed bad URL's in to the redirect. (Although I fail to see how this might be abused for malicious purposes. (but then again, I am not thinking at 100% capacity at the moment :P))
Newbie
 
Join Date: Nov 2008
Posts: 3
#4: Nov 3 '08

re: login then back to the previous page


Thanks alot guys!!!!
Reply