Jump to content

Recommended Posts

Hi guys,

 

I know that the script is ok but it just needs rearranging! I can't figure out how to do it.

 

Ok,

 

The code should do the following (in the following order):-

 

  • Connect to DB
  • Retrieve data where IP = Users IP AND DATE = Todays Date
  • If no results - Input new data into DB
  • Otherwise, there IS results & therefore check if user is exempt (Exempt=1).
  • User IS exempt - launch download - end script
  • User ISN'T exempt --> calculate total downloads
  • If downloads are used - echo 'Youre out of downloads'
  • If downloads spare - echo 'not out of downloads'

 

// DB connect
mysql_connect("localhost", "USERNAME", "PASSWORD") or die(mysql_error());

mysql_select_db("DB") or die(mysql_error());

// Retrieve all data
$query1 = mysql_query("SELECT * FROM table WHERE IP='$ip_address' AND DATE='$date'")
or die(mysql_error());  

if(mysql_fetch_array($query1)==0) {
// store the record into $row

// If no results, input new IP & DATE
mysql_query("INSERT INTO table 
(IP, DATE, DOWNLOADED, EXEMPT) VALUES('$ip_address','$date','','0') ") 
or die(mysql_error());  
}
elseif ( $row['EXEMPT'] == 1 ) {

echo 'You are exempt';
$fullPath = 'http://www.mysite.co.uk'.$path;
if ($fd = fopen ($fullPath, “r”)) {
$fname = basename($fullPath);
header('Content-type: text/plain');
header('Content-Disposition: filename="'.$fname.'"');
header('Cache-control: private'); 
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
fclose ($fd);
exit ();
}
} else {
// Calculate total downloads
$total = $row['DOWNLOADED'] + $filex;

if ( $total >= $max_downloads ) {

// This file will take them over their limit
echo 'Youre out of downloads!';

} else {
echo 'not out of downloads';
}
}

 

Many thanks for your help!

 

DoA

Link to comment
https://forums.phpfreaks.com/topic/70002-loop-help-please-tearing-hair-out/
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.