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

That will work fine, as you're redirecting after the MySQL query. It's also a good idea to always place exit; after a header redirect to ensure the execution of the script is stopped.

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.