Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-21-2008, 01:57 AM   PM User | #1
fl00d
Regular Coder

 
Join Date: Mar 2007
Location: Quebec
Posts: 261
Thanks: 6
Thanked 7 Times in 7 Posts
fl00d has a little shameless behaviour in the past
Return to previous page type function

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

Last edited by fl00d; 04-21-2008 at 02:03 AM..
fl00d is offline   Reply With Quote
Old 04-21-2008, 02:23 AM   PM User | #2
BWiz
Regular Coder

 
BWiz's Avatar
 
Join Date: Mar 2006
Location: Sol System
Posts: 471
Thanks: 7
Thanked 21 Times in 21 Posts
BWiz is an unknown quantity at this point
I don't think my method is very practical, but you could create a session variable, with each page having it's own unique identity. So, with the return option, it just looks at the session variable (which is redeclared on every page), and then matches the id too the correct link.

So something like:
inbox.php:
PHP Code:
<?php
/* This is at the top of the page */
session_start();
$_SESSION['return'] = "page_23";
?>
mailbox.php:
PHP Code:
<?php
session_start
();
if(
$_SESSION['return'] == "page_23") {
$link_back "index.php";
}
?>
...
<a href="<?php print $link_back?>">Return</a>
__________________
BWiz :: Happy Coding!
2006
2007 2008 2009
2010 2011
Irrational numbers make no sense.

Last edited by BWiz; 04-21-2008 at 03:19 AM..
BWiz is offline   Reply With Quote
Old 04-21-2008, 03:01 AM   PM User | #3
fl00d
Regular Coder

 
Join Date: Mar 2007
Location: Quebec
Posts: 261
Thanks: 6
Thanked 7 Times in 7 Posts
fl00d has a little shameless behaviour in the past
Actual your method makes a lot of sense. I'll admit, I did think of that, but I discarded it because if it is on every page, it would get overwritten. So when the time comes that the user is redirected to the 'You have a new message' page, the new URL would be the new message page... obviously, I just don't have to have new message page set a URL... silly me :P

Thanks I'll try it out.
fl00d is offline   Reply With Quote
Old 04-21-2008, 10:41 AM   PM User | #4
Arnaud
Regular Coder

 
Join Date: Jan 2008
Location: Geneva, Switzerland
Posts: 413
Thanks: 12
Thanked 29 Times in 29 Posts
Arnaud is on a distinguished road
What about setting your $_SESSION variable only once?

That would make sure the user is redirected to the first page he viewed on your website.

PHP Code:
<?
session_start
();
if (!isset(
$_SESSION['return'])) {
  
$_SESSION['return'] = $page;
}
?>
__________________
Chuck Norris counted to infinity.
Twice.
Arnaud is offline   Reply With Quote
Old 02-09-2010, 01:35 PM   PM User | #5
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,503
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
__________________
ZCE
kbluhm is offline   Reply With Quote
Old 02-09-2010, 04:13 PM   PM User | #6
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
Why can't you just use a visible message notifier somewhere on the page or a javascript alert/overlay etc? I'd personally find it bloody annoying to get shunted to a notification page every time there was a message, as I guess will a notable percentage of your users, once the novelty wears off.
MattF is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:05 AM.


Advertisement
Log in to turn off these ads.