CMC Posted April 21, 2008 Share Posted April 21, 2008 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 Quote Link to comment Share on other sites More sharing options...
PcGeniusProductions Posted April 21, 2008 Share Posted April 21, 2008 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. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Share Posted April 21, 2008 then if they come from an external site, have it echo a link to index.php on your site?? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 I think that phpBB/Invision forums pass it with $_GET or a session variable that it sets on the page from where you came from, like $_SESSION['lastpg']. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.