doa24uk Posted September 20, 2007 Share Posted September 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70002-loop-help-please-tearing-hair-out/ 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.