Jump to content

Using Php to veri


ds5010101

Recommended Posts

How do i make an site that could be visited 1 time by ip,

like if you visit second time, the site will be redirected to another webpage , like an front page of the site.

 

 

i now that i will use REMOTE_ADDR; and header, but i don't now how to communicate function together. it would be fine if i could get help..

Link to comment
https://forums.phpfreaks.com/topic/203092-using-php-to-veri/
Share on other sites

Hey,

 

You should create a table inside your database called IP Addresses and then when a user visits the site, insert the IP Address to the database, but just prior to this have PHP check to see if the IP address is already in the database, if it is then you can redirect the user away.

 

Be careful though, IP Addresses are rarely static It's possible that users who haven't visited the site before will get redirected away.

Link to comment
https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064172
Share on other sites

Ok so first create a table called ip_log with the fields 'id' - set to auto increment & int, 'ip' - set to char (15).

 

To check use

<?php

//Check if user has already visited
if(mysql_num_rows(mysql_query("select `ip` from ip_log where ip='" . $_SERVER['REMOTE_ADDR'] . "' limit 0, 1")) == 1) {

    //Redirect user
    header('Location: ...Location Here...');

} else {

    //Log visit
    mysql_query("insert into ip_log (`ip`) values ('" . $_SERVER['REMOTE_ADDR'] . "')");

}

?>(

 

Place the rest of the site below, and don't forget to set the database login details.

 

Link to comment
https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064239
Share on other sites

i have 1 last question:P

 

can i add:

header("location: www.example.com"); inside else ?

 

like this

 

<?php

 

//Check if user has already visited

if(mysql_num_rows(mysql_query("select `ip` from ip_log where ip='" . $_SERVER['REMOTE_ADDR'] . "' limit 0, 1")) == 1) {

 

    //Redirect user

    header('Location: ...Location Here...');

 

} else {

 

    //Log visit

    mysql_query("insert into ip_log (`ip`) values ('" . $_SERVER['REMOTE_ADDR'] . "')");

  header('Location: ...Location Here...');

 

}

 

?>(

 

Will it put the ip inside database? or will it redirect without nothing.

 

Link to comment
https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064313
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.