Current location: Hot Scripts Forums » General Community » Script Requests » Open page once per day per IP


Open page once per day per IP

Reply
  #11 (permalink)  
Old 09-21-09, 12:18 PM
CyBeRaY84 CyBeRaY84 is offline
New Member
 
Join Date: Sep 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by LooieENG View Post
Create a database with this structure

table name: logs
column 1 name: ip
column 1 type: varchar(15)
column 2 name: time
column 2 type: int

and on the page you want to protect, use this

PHP Code:

<?php


mysql_connect
('localhost''MYSQLUSERNAME''MYSQLPASSWORD');
mysql_select_db('MYSQLDATABASENAME');

mysql_query('DELETE FROM `logs` WHERE ' . (time() - 86400) . ' >= `time`');

if (
filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP)) {
        
$result mysql_query('SELECT `time` FROM `logs` WHERE `ip` = "' $_SERVER['REMOTE_ADDR'] . '"');
        if (
mysql_num_rows($result) === 0) {
                
mysql_query('INSERT INTO `logs` VALUES ("' $_SERVER['REMOTE_ADDR'] . '", ' time() . ')');

?>

<!-- display your html code here. if you need to use PHP, do it like this -->

<div id="blah">blah, this is some html but wait, I need <?php echo 'PHP!' ?>!</div>

<?php

        
} else {
                exit(
'Sorry, you have already visited this page in the last 24 hours!');
        }
} else {
        exit;
}

?>
That should work
I need this so much but it doesn't work. It gives error:

Fatal error: Call to undefined function: filter_var() in /home/bdvsms/public_html/ipban.php on line 8
Reply With Quote
  #12 (permalink)  
Old 09-21-09, 04:07 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
Your using a version of PHP before 5?
__________________
This post was created with 100% recycled electrons.
Reply With Quote
  #13 (permalink)  
Old 09-21-09, 05:19 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
My hosting company has PHP4 as the default, with PHP5 available by extension (.php5).

It is understandable that shared servers may not be upgraded, because many PHP4 applications won't run under PHP5.

Instead of filter_var, you should be able to find some code to validate the IP address.
Reply With Quote
  #14 (permalink)  
Old 11-23-11, 03:56 AM
shakeebfarhat shakeebfarhat is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hello @ carters-site's your script is awesome..can u a little bit modify it...rather to redirect to GOOGLE.COM the page it self close....can any one help me...i need it badly plzzzzz
Reply With Quote
  #15 (permalink)  
Old 11-23-11, 03:59 AM
shakeebfarhat shakeebfarhat is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Question NEed Help Plzzzz

Quote:
Originally Posted by carters-site View Post
Working Javascript method (cookie based)

Code:
  <script language ='javascript'>
   function createCookie(name,value,days) {
   	if (days) {
   		var date = new Date();
   		date.setTime(date.getTime()+(days*24*60*60*1000));
   		var expires = "; expires="+date.toGMTString();
   	}
   	else var expires = "";
   	document.cookie = name+"="+value+expires+"; path=/";
   }
   
   function readCookie(name) {
   	var nameEQ = name + "=";
   	var ca = document.cookie.split(';');
   	for(var i=0;i < ca.length;i++) {
   		var c = ca[i];
   		while (c.charAt(0)==' ') c = c.substring(1,c.length);
   		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   	}
   	return null;
   }

   /* Check the cookie and redirect if they have it set. */   
   
   sWhere = 'http://google.com';  // replace this with where you want them to be sent when they can't view page. 

   if(!readCookie('viewcheck')){
      createCookie('viewcheck',1,1);
   } else {
      window.location = sWhere;
   }
</script>

Borrowed cookie code from JavaScript - Cookies
Hello @ carters-site's your script is awesome..can u a little bit modify it...rather to redirect to GOOGLE.COM the page it self close....can any one help me...i need it badly plzzzzz
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
open word file in a specific asp.net page mariowowo ASP.NET 1 06-28-08 01:47 AM
External link to open in same page sparkiii Script Requests 7 03-27-07 03:15 AM
depending on the day is the page displayed pkcidstudio Script Requests 7 08-22-06 05:05 PM
Page reload (Another is this possible) chrisrobertson HTML/XHTML/XML 0 07-31-06 07:30 PM
Open feed back page pallabmondal123 JavaScript 2 03-06-06 02:38 PM


All times are GMT -5. The time now is 09:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.