a rare code?

Status
Not open for further replies.

Terminator

Member
May 2, 2012
52
11
i dont know if its rare or not

but i need a code that you can view once a day and once you been there it redirects you the second time!
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
You could create a database, log all IP's visiting the website and log it with a time stamp, make the website delete every IP address that was entered over 24 hours ago when a user refreshes the page. Then when they load the page, have a code which will check their IP address against the database, if it has been found then redirect them, if not. So basically:

PHP:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
 
/* delete ips from over 24 hours ago */
mysql_query( "DELETE FROM `ip` WHERE `time` < '" . (time() - 86400) . "" );
/* delete ips from over 24 hours ago */
 
$check_ip = mysql_query( "SELECT * FROM `ip` WHERE `IPAddress` = '" . $ip . "'" );
if ( (int) mysql_num_rows($check_ip ) == 1 )
{
    header("Location: redirect_page.html" );
}
else
{
    mysql_query( "INSERT INTO `ip` (`IPAddress`, `time`) VALUES ('" . $ip . "', '" . time() . "')" );
}
?>

It's poorly coded and probably doesn't work, but I'm hoping you get the jist.

The only bad thing about this method is with multiple people on the same IP Address -- it will block them if the IP Address is already in the database even though it may not have been them that visited the site.
 

Terminator

Member
May 2, 2012
52
11
You could create a database, log all IP's visiting the website and log it with a time stamp, make the website delete every IP address that was entered over 24 hours ago when a user refreshes the page. Then when they load the page, have a code which will check their IP address against the database, if it has been found then redirect them, if not. So basically:

PHP:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
 
/* delete ips from over 24 hours ago */
mysql_query( "DELETE FROM `ip` WHERE `time` < '" . (time() - 86400) . "" );
/* delete ips from over 24 hours ago */
 
$check_ip = mysql_query( "SELECT * FROM `ip` WHERE `IPAddress` = '" . $ip . "'" );
if ( (int) mysql_num_rows($check_ip ) == 1 )
{
    header("Location: redirect_page.html" );
}
else
{
    mysql_query( "INSERT INTO `ip` (`IPAddress`, `time`) VALUES ('" . $ip . "', '" . time() . "')" );
}
?>

It's poorly coded and probably doesn't work, but I'm hoping you get the jist.

The only bad thing about this method is with multiple people on the same IP Address -- it will block them if the IP Address is already in the database even though it may not have been them that visited the site.

Marry me.

Edit: divorce time doesnt work! But thanks for the try bro - Respect homie +
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
yup but the problem is its not creating any tables or values.
Is the code connected to the database?
Are the table name and fields in the code the same as the ones in the actual database?
Is it throwing any errors?

If not, the code is fubar.
 
Status
Not open for further replies.

Users who are viewing this thread

Top