Need to combine 2 PHP Scripts Included With Explanation

JesterJoker

Regular Member
Joined
Jan 13, 2008
Messages
238
Reaction score
28
Script 1:

This script checks my database if the IP address matches one for a previous visitor to my page, and redirects them to another page so they cannot see the original content the went to, to begin with.

PHP:
<?php

$vis_ip = $_SERVER["REMOTE_ADDR"]; // the user's IP address
$vis_url = $_GET["url"]; // the URL they have visited
$vis_agent=$_SERVER["HTTP_USER_AGENT"]; //user agent
$vis_lang=$_SERVER["HTTP_ACCEPT_LANGUAGE"]; //accept language
$vis_ref=$_SERVER["HTTP_REFERER"]; //referer

$vis_hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);


$sql=mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databaseName")or die(mysql_error());


$sql_query = mysql_query("SELECT `id_stat` FROM `stats` WHERE `vis_ip` like '$vis_ip' ");//check IP in database


$rows = mysql_num_rows($sql_query);

if($rows>0)

      {

      header('Location: redirected.php');

      }

      else {$found=false;}
	  
?>


I need to combine that with this script.

This script checks the referer to see if its from a specific page and displays my whitehat or blackhat page depending on that, but before this point I want it to check the IP address with the script above this one and redirect them completely as a safeguard. As visitors come to my site they are logged by ip and hostname so that record that is stored on visit 1 is what is being referenced. This is part of a chameleon script to hide the originating page. So as example the script below would be called index.php And the chameleon script that references it would be the 12345.php page.


PHP:
<?php

$referer = $_SERVER['HTTP_REFERER'];
if($referer == "http://www.site.com/12345.php")
{
echo "
<html>


<title>Blackhat Page</title>
</head>

<body>
<center>
<h2>BlackhatPage</h2>
</center>



</body>
</html>

";
}
else
{
echo "

<html>


<title>whitehat page</title>
</head>

<body>
<center>
<h2>Whitehat Page</h2>
</center>

</body>
</html>


";
}
?>
 
Last edited:
Now that I have looked into the script further, I'm starting to wonder if filtering the traffic in the 12345.php file is the way to go?


Heres that file in case.

It might be a standard elseif or if else? to make this work the way I want.

This would be the above file, called 12345.php

PHP:
<body onLoad="javascript:frmForcedReferrer.submit();">
<form action="http://www.site.com/index.php" method="post" name="frmForcedReferrer">
</form>
 
PHP:
<?php
$vis_ip = $_SERVER["REMOTE_ADDR"]; // the user's IP address
$sql=mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databaseName")or die(mysql_error());
$sql_query = mysql_query("SELECT `id_stat` FROM `stats` WHERE `vis_ip` like '$vis_ip' ");//check IP in database
$rows = mysql_num_rows($sql_query);
if($rows>0)
{
echo "
<html>
<title>Blackhat Page</title>
</head>
<body>
<center>
<h2>BlackhatPage</h2>
</center>
</body>
</html>
";
}
else
{
echo "
<html>
<title>whitehat page</title>
</head>
<body>
<center>
<h2>Whitehat Page</h2>
</center>
</body>
</html>
";
}
?>
 
ok this got me thinking now????, whether I need that url check, but I'm sure I do since I want to block the traffic, but really its being blocked by ip address anyway by doing this.???


But what about checking if the traffic is coming from the 12345.php page?
That can just be slapped in there right? But where on the top?

because I still want to show the pages black/whitehat / as long as the 1st url, the 12345.php page has not been visited, or another page like that.

and in the original file, the checking for that url is integral for the
showing of the black/white hat page right?

i.e.

original use of the script.

visitor hits the 12345.php page, they are directed to index.php BUT view the "Blackhat section of the script"
There clicks on the page are registered as index.php to an affiliate, but if you visit index.php directly it shows another page the "Whitehat page" with my affiliate links on it as a cover.


Jester
 
Last edited:
is
PHP:
$vis_ip = $_SERVER["REMOTE_ADDR"]; // the user's IP address
$vis_url = $_GET["url"]; // the URL they have visited
$vis_agent=$_SERVER["HTTP_USER_AGENT"]; //user agent
$vis_lang=$_SERVER["HTTP_ACCEPT_LANGUAGE"]; //accept language
$vis_ref=$_SERVER["HTTP_REFERER"]; //referer
$vis_hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$sql=mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("databaseName")or die(mysql_error());
$sql_query = mysql_query("SELECT `id_stat` FROM `stats` WHERE `vis_ip` like '$vis_ip' ");//check IP in database
$rows = mysql_num_rows($sql_query);
if($rows>0)
      {
      header('Location: redirected.php');
      }
      else {$found=false;}
?>

the 12345.php page?

If so, then it is included in what I gave you earlier.
</span></span>
 
Yes it is the page.. but where in your code does it redirect to redirected.php?


Maybe im missing something.. i write out exactly what it needs to do it might be doing it all ready and i might be missing it.
 
Right now, it doesnt redirect you, it does the filtering on the page. As it stands, if your credentials are in the database -- (mysql_num_rows > 0), it shows you the blackhat page. Otherwise, it shows you the whitehat page.
 
OK thats what I thought.


This is what I was trying to accomplish.

Check referer of 12345.php

Redirect to index.php

- If 12345.php is referer show blackhat section
- But check ip address if in database show redirected.php instead of blackhat section
because I dont want to have them to be able to load the black hat page again

- If index.php is loaded directly show whitehat section



But then the thing I cant decide on should I block the index.php file to be directly loaded? in case the original visitor checks the history and sees index.php and then sees a totally different site when they load it again with no referer of 12345.php
 
I think you're only wanting any visitor to only ever see the blackhat page once.

If so, I would do this:

index.php will have two display modes: blackhat and whitehat.
On first load, index.php will check their ip, if it is in the database because they have visited before, index.php will print out the whitehat page.
If their ip is not in the database, show the blackhat page and log their ip address.

I'm not sure how the reference from 12345.php plays in. Some people will see teh blackhat page more than once?

If you can, pm me your messenger name and I can help fix your problems much quicker.
 
Back
Top