Jump to content

Return to previous page type function


CMC

Recommended Posts

Hi,

 

I'm writing a return to previous page type function like phpBB, SMF, VB and the likes implement. Someone wants me to implement it into their PM system so it would work like so:

 

When the user first visits the site and logs in, if they have a new/unread PM, they will be redirected to a page that says 'You have a new PM | Read | Return'. They have the option to click read, which brings them to the PM, or the option to 'Return', which returns them to the page they were previously viewing or trying to view. This is the part I'm having trouble with, I don't know how to effectively capture the previous page. I've thought up a couple methods, but none are terribly efficient nor effective.

 

1) Use Javascript history.go(-1)

Problem: If they enter from another site (ex: google.com), they will be returned to Google. I don't want to kick them off my site...

 

2) Use HTTP_REFERRER

Problem: May not be stored or again could be another site, not part of my own. I could fix this by checking if their is a HTTP_REFERRER, and then preg_match or search it for my host name and if not found, set a 'static' page to go to.

ex:

if(empty(REFERRER)){
  $url = 'mysite.com/members.php';
}else{
  
  $find = '^mysite.com';
  if(!preg_match($find,REFERRER)){
    $url = 'mysite.com/members.php';
  }
}
header("Location: $url");

 

Anyone have any better suggestions or how-to's?

 

Thanks

-fl00d

Link to comment
Share on other sites

Hi, Might not be exactly what your looking for, but I dropped in and saw what you needed...

 

if (isset($HTTP_REFERER)) {

echo "<a href='$HTTP_REFERER'>back</a>";

} else {

echo "<a href='javascript:history.back()'>back</a>";

}

 

It may need tweeking, but is this what you wanted?

 

I am semi-concous right now, but It should check to make sure the history is there before allowing it.

Link to comment
Share on other sites

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.