ds5010101 Posted May 27, 2010 Share Posted May 27, 2010 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.. Quote Link to comment https://forums.phpfreaks.com/topic/203092-using-php-to-veri/ Share on other sites More sharing options...
GetPutDelete Posted May 27, 2010 Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064172 Share on other sites More sharing options...
ds5010101 Posted May 27, 2010 Author Share Posted May 27, 2010 i am new to php, so could you show me how, is it complicated? or could you find an tutorial? Quote Link to comment https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064187 Share on other sites More sharing options...
GetPutDelete Posted May 27, 2010 Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064239 Share on other sites More sharing options...
ds5010101 Posted May 27, 2010 Author Share Posted May 27, 2010 Thanks man you rock ! :D :D :D Quote Link to comment https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064308 Share on other sites More sharing options...
ds5010101 Posted May 27, 2010 Author Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064313 Share on other sites More sharing options...
Alex Posted May 27, 2010 Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064325 Share on other sites More sharing options...
ds5010101 Posted May 27, 2010 Author Share Posted May 27, 2010 thanks sir, i am new to php:P learning learnin.. xD Quote Link to comment https://forums.phpfreaks.com/topic/203092-using-php-to-veri/#findComment-1064327 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.