Jump to content

$_SERVER['HTTP_REFERER'] is there a better solution??


Recommended Posts

Hello all,

 

I have been looking into using $_SERVER['HTTP_REFERER'] to populate the href of a back link.

 

I thought this would be a good idea as I have a login page that can be accessed from pretty much every page on my site. I wanted the user to be able to go back to the page they last viewed before they logged in.

 

eg.

The user has browsed to the gallery page as a guest. They then decide they wish to upload an image. Uploading images can only be done by a logged on user. So they click the login link at the top of the page. They login, a message is displayed saying welcome and they are presented with a back link or button.

 

So I was thinking:

 

<form action="<?php echo $_SERVER['HTTP_REFERER']; ?>"><input type="submit" value="Back" /></form>

 

or

 

<a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Back</a>

 

Is there a better way?

 

Many Thanks

The only other possible idea is to pass the previous URL via sessions, cookies or URL. HTTP_REFERER is sometimes reconfigured in the browser to pass different address than it is supposed to, but actually you should not be worried about that. If someone has such stupid ideas as using the protocol fields for different purposes, he should not be surprised that something does not work for him.

is there a better solution??

 

Yes, think of the log in as a 'box' or a code block that you include on any page that needs it (such as the way this forum handles the log in.)

 

If the visitor is not logged in, the log in form is displayed in a specific region on the page. The log in form submits back to the current page. The code that processes the log in form is part of the code block that you included on the page. If you are logged in, the username and a log out link/menu is displayed instead.

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.