Jump to content

IPs


ShaolinF

Recommended Posts

Hi Guys,

 

I want to write a script where if a user visits the website, the IP is logged. Now if the user visits the same page again, he is redirected to another page. This is specifically aimed at my static IP users.

 

How can I do this ?

Link to comment
Share on other sites

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
Share on other sites

IP addresses can change.

Cookies can't. (Without humans.)

 

if (isset($_COOKIE[visit]) {
header('Location: page.php'); 
}
elseif (empty($_COOKIE[visit])) {
echo 'This is your first time visiting this page.'; 
}

 

Try that.

Link to comment
Share on other sites

eeek..

Sorry for that.

 

Thanks. I tried it and I get the following error:

 

Parse error: syntax error, unexpected '{' in /home/****/public_html/login/grab.php on line 3

 

Line 3 is:

if (isset($_COOKIE[visit]) {

Link to comment
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
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
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
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
Share on other sites

<?php

 

$value = 'visit';

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

 

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

header('Location: ValidateCaptchaForResetPasswd.htm');

}

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

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

}

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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