Skip to main content
Known Participant
August 5, 2011
Answered

using an absolute link in php

  • August 5, 2011
  • 1 reply
  • 634 views

I have a login form that I created with dreamweaver and I want the script to send the user, on a successful login, back to the page where he came from.

the php code dreamweaver created is (part):

$MM_redirectLoginSuccess =" ";

and I stuck in the $_SERVER['HTTP_REFERER'] to get:

$MM_redirectLoginSuccess = '"'. $_SERVER['HTTP_REFERER']. '"';

yet the HTTP_REFERER is an absolute link (http://www.example.com/...) while the php thinks it is getting a relative link.

therefore I get the error:

Forbidden

You don't have permission to access /pages/"http://www.example.com/whatever.php" on this server.

Is there an easy way to rectify this?

thanks,

YWSW

P.S. the code $MM_redirectLoginSuccess = $_SERVER['HTTP_REFERER']; (without the quotations) does not work at all.

This topic has been closed for replies.
Correct answer Ben M

Best thing to do is research sessions.  The following is a brief tutorial on sessions:

http://www.tizag.com/phpT/phpsessions.php

What you need to do is start a session before the process starts and include the session script on every page of your site.  As long as the user has an active session keep writing to that session with the page name that the user navigated to.  Then when they decide to go to the login page, store the last page and when the user is done you have the root relative link to get back there such as ../pathto/file.html.  Using an absolute reference is no really necessary if you always have a root relative link to page the user was on.

1 reply

Ben MCommunity ExpertCorrect answer
Community Expert
August 6, 2011

Best thing to do is research sessions.  The following is a brief tutorial on sessions:

http://www.tizag.com/phpT/phpsessions.php

What you need to do is start a session before the process starts and include the session script on every page of your site.  As long as the user has an active session keep writing to that session with the page name that the user navigated to.  Then when they decide to go to the login page, store the last page and when the user is done you have the root relative link to get back there such as ../pathto/file.html.  Using an absolute reference is no really necessary if you always have a root relative link to page the user was on.

YWSWAuthor
Known Participant
August 7, 2011

just tried it and it works perfectly.

I stored $_SESSION['currentPage'] = $_SERVER['REQUEST_URI']

and when I reach the login page I set it that the $_SESSION['currentPage'] should not be $_SERVER['REQUEST_URI'] thus I have the previous page still in the 'currentPage' session variable which I then use to send the user after a successful login.

thanks a ton.