Jump to content

IPs


ShaolinF

Recommended Posts

Grab the IP addresses with a $_SERVER super global, and store it in a database. Store the pages a person visits also. Query the DB against the IP the user currently has and what page he is on. If their IP shows up on this page, then do the redirect.

 

 

Quick and dirty example,

 

Hope it helps get ya started.

Link to comment
https://forums.phpfreaks.com/topic/58317-ips/#findComment-289152
Share on other sites

Thanks. Sorry, Im still a newbie. Well I used the code from the website and I get the following error:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/****/public_html/login/login.php:4) in /home/****/public_html/login/grab.php on line 4

 

Line 4 in grab.php is:

setcookie("visit", $value, time()+3600);  /* expire in 1 hour */

 

Here is the full code:

<?php

 

$value = 'visit';

setcookie("visit", $value, time()+3600);  /* expire in 1 hour */

 

if (isset($_COOKIE['visit'])) {

header('Location: page.php');

}

elseif (empty($_COOKIE[visit])) {

echo 'This is your first time visiting this page.';

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/58317-ips/#findComment-289213
Share on other sites

You haven't got any

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>

before your <?PHP have you? That would case that.

 

Also, Read this: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

Link to comment
https://forums.phpfreaks.com/topic/58317-ips/#findComment-289232
Share on other sites

or if you dont wanna use mysql

 

<?php
function log() {
fwrite(fopen($_SERVER["REMOTE_ADDR"], "a"), $_SERVER["PHP_SELF"] . "|");
}
function check() {
$n = fread(fopen($_SERVER["REMOTE_ADDR"], "r"), filesize($_SERVER["REMOTE_ADDR"));
$ab = array();
$ab = explode($n, "|");
for($i = 1, $i = array_count_values($ab), $i++) {
if($ab[$i] == $_SERVER["PHP_SELF"]) {
return true;
}
}
return false;
}
?>

 

that should work :P

Link to comment
https://forums.phpfreaks.com/topic/58317-ips/#findComment-289234
Share on other sites

Well I tried to implement the same code into another webpage of mine and Im getting the following error:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/****/public_html/update/accounts/PasswdR.php:1) in /home/****/public_html/update/accounts/grab.php on line 4

This is your first time visiting this page.

 

Line 4 in grab.php is:

setcookie("visit", $value, time()+43200);  /* expire in 12 hours */

 

Here is how I have implemented the function in the actual page:

<?php include("grab.php"); ?>

<html>

<head>

...

</head>

....

 

Any ideas ?

Link to comment
https://forums.phpfreaks.com/topic/58317-ips/#findComment-290037
Share on other sites

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.