Lamez Posted January 17, 2010 Share Posted January 17, 2010 Is there a way to see what the last page the user requested? Say I go to the phpfreaks website, then I go to my script, and my script displays: phpfreaks.com or phpfreaks.com/forums/index.php?action=post. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/ Share on other sites More sharing options...
Buddski Posted January 17, 2010 Share Posted January 17, 2010 $_SERVER['HTTP_REFERER']; The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996420 Share on other sites More sharing options...
oni-kun Posted January 17, 2010 Share Posted January 17, 2010 Is there a way to see what the last page the user requested? Say I go to the phpfreaks website, then I go to my script, and my script displays: phpfreaks.com or phpfreaks.com/forums/index.php?action=post. Thanks! You can log the variable $_SERVER['HTTP_REFERRER'] and that should tell you the page they were on when they pressed a link to your page. You can create a script on your server named ref.php and place <?php echo '<pre>'; echo print_r($_SERVER); ?> And put it in your sig, and press the link and it should show ALL available variables that follow with HTTP_REFERRER for your information. If you want to log it to a file, I can show you an example script (simple html log). But just remember many referrers are blocked by default, as they are sent by the client and may be disabled (even spoofed) for any reason. Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996422 Share on other sites More sharing options...
Lamez Posted January 17, 2010 Author Share Posted January 17, 2010 See I did that, and it did not turn out the way I wanted, but maybe it is my code structure. What I am doing is making a login script to force users to login to use my internet via HTTP requests. I think I am going to rewrite it for the third time here is what I have so far: <?php include('gatewayLogin.php'); ob_start(); session_start(); echo '<title>My Internets</title>'; function checkHost($host){ $q = mysql_query("SELECT * FROM allowed_host WHERE hostname = '$host'"); $n = mysql_num_rows($q); if($n > 0){ if(justDay <= (justDay()+5)){ return true; }else{ removeHost($host); return false; } }else{ return false; } } function allowHost($host){ if(!checkHost($host)){ $date = justDay(); $time = currentTime(); mysql_query("INSERT INTO allowed_host (hostname, date, time) VALUES ('$host', '$date', '$time')"); $_SESSION['allow'] = $host; } } function removeHost($host){ if(checkHost($host)){ mysql_query("DELETE FROM allowed_host WHERE hostname = '$host'"); } } function getPassword(){ $q = mysql_query("SELECT password FROM password"); $n = mysql_num_rows($q); if($n > 0){ $f = mysql_fetch_array($q); return $f['password']; } } function justDay(){ return date("j"); } function currentDate(){ return date("M j Y"); } function currentTime(){ return date("g:i a"); } function logInfo($host, $value){ $date = currentDate(); $time = currentTime(); mysql_query("INSERT INTO logs (hostname, date, time, value) VALUES ('$host', '$date', '$time', '$value')"); } $host = $_SERVER['REMOTE_ADDR']; if($_GET['cmd'] == "check"){ if(md5($_POST['password']) === md5(getPassword())){ allowHost($host); header("Location: ?"); }else{ if(isset($_SESSION['failLimit']) && $_SESSION['failLimit'] >= 5){ logInfo($host, "Reached Fail Limit"); header("Location: ?cmd=limit"); }else if(isset($_SESSION['failLimit'])){ $_SESSION['failLimit']++; }else{ $_SESSION['failLimit'] = 0; } logInfo($host, "Incorrect Password"); header("Location: ?show=fail"); } }else if($_GET['cmd'] == "limit"){ echo '<font color="red">You have reached the limit on incorrect passwords, try again later!</font>'; }else if($_GET['cmd'] == 8675309){ unset($_SESSION['failLimit']); unset($_SESSION['allow']); header("Location: ?"); }else{ if(isset($_SESSION['allow']) && $_SESSION['allow'] == $host){ header("Location: http://www.google.com"); }else{ if($_GET['show'] == "fail"){ echo '<font color="red">The password you entered is incorrect.</font>'; } if(checkHost($host)){ if(isset($_GET['url'])){ header("Location: http//".$_GET['url']); }else{ header("Location: http://www.google.com"); } }else{ echo ' <form action="?cmd=check" method="post" />Enter Password: <input type="password"" name="password" /><input type="submit" name="submit" value="Login" /></form>'; } } } echo "<br /><i>".currentDate()."</i> - <i>".currentTime()."</i>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996424 Share on other sites More sharing options...
trq Posted January 17, 2010 Share Posted January 17, 2010 Can you actually describe your problem? Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996436 Share on other sites More sharing options...
Lamez Posted January 17, 2010 Author Share Posted January 17, 2010 Sure. Redirect Loop. But I think I have it fixed now. Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996441 Share on other sites More sharing options...
oni-kun Posted January 17, 2010 Share Posted January 17, 2010 include('gatewayLogin.php') ob_start(); session_start(); You're starting the session after a file is included? But yes.. what are you wanting to implement with the referrer? Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996443 Share on other sites More sharing options...
Lamez Posted January 17, 2010 Author Share Posted January 17, 2010 Sure, sorry to keep you guys guessing. That was not my intention. 1. User Tries to access the internet w/ a request URL (www.google.com/search?hl=en&site=&q=my+small+kitty&btnG=Search) 2. User request is intercepted, and is forced to enter a password to continue. -1a. User fails to enter the correct password within the fail limit of five. --1a.User must wait until the session has expired to try again, and will not be able to continue. -2a. User correctly enters the password within the fail limit of five. --1a. IP address is entered into the database, and is redirected to the request (www.google.com/search?hl=en&site=&q=my+small+kitty&btnG=Search) That is a shorter version of what I am trying to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996452 Share on other sites More sharing options...
trq Posted January 17, 2010 Share Posted January 17, 2010 So your not after the referring url at all, your looking for the url the user typed to get to your script? In a sense your writing an LAN based proxy that will prompt a user for a password before allowing there request to continue out into the WAN? Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996456 Share on other sites More sharing options...
Lamez Posted January 17, 2010 Author Share Posted January 17, 2010 Yes, but not a proxy. The router (w/ DD-WRT) will intercept the request, and then run the script, then continue. I have a problem with this though. Each HTTP request will be intercepted even if they are allowed to browse. (see this: http://www.dd-wrt.com/phpBB2/viewtopic.php?t=64777) So the script will check, and set a session variable if is not set. Do you have any alternatives? I do have a proxy server running Squid3. It is only caching at the moment (it is transparent). Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996465 Share on other sites More sharing options...
Lamez Posted January 18, 2010 Author Share Posted January 18, 2010 I wonder if Squid3 allows this sort of thing. Quote Link to comment https://forums.phpfreaks.com/topic/188755-requesting-the-visitors-last-page-visit/#findComment-996960 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.