PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 7th, 2008, 02:34 PM
sg552 sg552 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 27 sg552 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 8 m 31 sec
Reputation Power: 0
Question Limit number of downloads per IP

Hi,

This is my first post in this forum. What this code suppose to do is to check whether user has download more than 3. If < 3 they will redirect to download.php page but if = 3 user will be redirect to index.php page.

This is the closes I can get but still one error left... what is wrong this code...

PHP Code:
<?php
// every page needs to start with these basic things

// I'm using a separate config file. so pull in those values
require("config.inc.php");

// pull in the file with the database class
require("database.class.php");

// create the $db ojbect
$db = new Database($config['server'], $config['user'], 
                   
$config['pass'], $config['database'], $config['tablePrefix']);

// connect to the server
$db->connect();

$config['download_limit'] = 3;

// check database for their IP
$sql "SELECT count(*) AS number FROM ".$db->pre."downloads
          WHERE ip='$_SERVER[REMOTE_ADDR]'"
;

$iplocked $db->query_first($sql);

// check to see if IP and/or cookie is over the limit
if($iplocked['number'] >= $config['download_limit'] || 
$_COOKIE['download_limit'] >= $config['download_limit']){
ob_start();
    echo 
"over user limit error";
    
// YOU: exit or redirect them
        
header("Location: http://www.mypage.com/index.php");  
         
ob_flush();
}
// they're good to go. allow download
else{
    
// insert their ip into database
    
$data = array('ip'=>$_SERVER['REMOTE_ADDR'], 'time'=>time());
    
$db->query_insert("downloads"$data); 

    
// set a cookie too
    
setcookie("download_limit", ($_COOKIE['download_limit']+1), time() + 24 3600);

    
// YOU: send the user to the file
    
header("Location: http://www.mypage.com/download.php"); 
      
}



// and you're done, remember to close connection
$db->close();


This is what I run in phymyadmin:

Code:
CREATE TABLE `downloads` (
  `id` int(11) auto_increment,
  `ip` varchar(15) NOT NULL,
  `time` TIME NOT NULL,
  PRIMARY KEY  (`id`)
)


This is the error:

Code:
Database Error 
Message: Result ID: 1 could not be freed. 
Date: Sunday, September 7, 2008 at 2:38:27 PM 
Script: /lol/test.php 


or view error image here > http://www.freeimagehosting.net/uploads/92954369b4.png


Any idea what Result ID : 1 could not be freed might be?? Problem with php code or database

Thanks in advance.

Last edited by sg552 : September 8th, 2008 at 01:27 PM. Reason: picture gone?

Reply With Quote
  #2  
Old September 8th, 2008, 09:26 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Beware
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Oct 2006
Location: Texas, USA
Posts: 2,358 ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level)ManiacDan User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 8 h 16 m 20 sec
Reputation Power: 548
Do you ever call mysql_free_result() from your database code? That's probably it. Otherwise, sounds like a database error. What database are you using?

-Dan
Comments on this post
sg552 agrees: thanks for helping me
__________________
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

If I have nothing to hide, you have no reason to search me.

Reply With Quote
  #3  
Old September 8th, 2008, 01:22 PM
sg552 sg552 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 27 sg552 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 8 m 31 sec
Reputation Power: 0
Question

I try to use the mysql_free_result() it still give me error.

PHP Code:
// connect to the server
$db->connect();

$config['download_limit'] = 3;

// check database for their IP
$sql "SELECT count(*) AS number FROM ".$db->pre."downloads
          WHERE ip='$_SERVER[REMOTE_ADDR]'"
;
          
$iplocked $db->query_first($sql);

/* Now we free up the result and continue on with our script */        
mysql_free_result($iplocked['number']);        

// check to see if IP and/or cookie is over the limit
if($iplocked['number'] >= $config['download_limit'] || 
$_COOKIE['download_limit'] >= $config['download_limit']){ 


So since $iplocked['number'] will compare with $config['download_limit'] so I use them in mysql_free_result. Any idea

I use mysql by the way. If you have any code that can limit user download similar like this please reply here. Thanks in advance

Reply With Quote
  #4  
Old September 10th, 2008, 11:56 PM
sg552 sg552 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 27 sg552 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 8 m 31 sec
Reputation Power: 0
Problem solved thanks for all the help!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Limit number of downloads per IP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT