Jump to content

Requesting the visitors last page visit.


Lamez

Recommended Posts

$_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.

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! :P

 

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.

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>";
?>

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.

 

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.