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:
PHP Code:
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