Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

using an absolute link in php

Community Beginner ,
Aug 05, 2011 Aug 05, 2011

Copy link to clipboard

Copied

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.

TOPICS
Server side applications

Views

555
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2011 Aug 06, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 06, 2011 Aug 06, 2011

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines