PHP - Mass Mysql Downloading - What's The Most Efficient Way Through Php?
I have dozens of tables that a client needs to download through the web. I can use PHP to convert the tables within the database to a CSV however I have to split the files into 10k result chunks otherwise the server gets overloaded with memory.
I already raised the memory limit within the script that is downloaded (ini_set('memory_limit', '512M') which is able to make this happen. Downloading these files piece by piece is a really time consuming. Is there a memory safe and efficient way to combine all my tables as CSV's and into one zip them into one master download? PHPMyAdmin seems to do this smoothly, however, I need an online interface for the client to export the data directly... Similar TutorialsProblem: I'm trying to build a junction table for a many to many relationship. Table A contains a title string that contains in it names that are stored in Table B. Both tables have nearly a million rows. Bad solution: The method I'm using right now is using PHP I fetch and store one table into an associative array. I then do a mysql_fetch loop on the second table and run this code to populate an array that is used to build the multi-insert SQL. $title = preg_replace ($names, $keys, $title); if (preg_match_all ('/(\d+)/', $title, $matches)) foreach ($matches[1] as $m) $inserts[$row['id'].'-'.$m] = 1; This works, but I'm looking for possibly a less cpu/memory intensive method. My remote server can't handle it, and we're talking hours and hours on a local server. It seems the bottleneck is with the preg_replace. I've also tried str_replace, which is only slightly faster. So, a method where I wouldn't have to pass around such large arrays, or an entirely different approach is what I'm looking for. Any ideas? I have an auctions website and I want to create a feature that is similar to ebay in which users will receive an email if one of the auctions they are watching will end in less than 3 hours. I will be using a cron job to call up this page every 15 minutes. When the cron job executes, I would like it to send 1 email per auction to every user that has that auction on their watchlist if the auction will be ending in 3 hours. I don't know whether it needs to be a separate email for each user or one mass email where their emails are hidden. The 4 tables in my database we are concerned about are "auctions, "users, "watchlists" and "products." I am trying to use the script phpMailer to execute the code because I heard it was the best one. Anways here is what I have so far. I am missing alot because I had no clue what to do. <?php require("class.phpmailer.php"); $holder = mysql_connect("localhost", "user", "password"); mysql_select_db("database", $holder); // NEED TO FIX THIS // Need to get ALL of the auction id's where the end time is less than 3 hours and the notification hasn't already been sent // $auctionid = mysql_query("SELECT id FROM auctions WHERE DATE_ADD(NOW(), INTERVAL 3 HOUR) <= end_time AND notification = 0", $holder); // get the auction title of EACH of the auctions selected above which is not stored in the auctions table but in the products table..will be used for body of email /// AGAIN, NEED THIS TO GET ME ALL OF THE NAMES OF AUCTIONS THAT ARE ENDING IN 3 HOURS// $auctiontitle = mysql_query("SELECT name FROM products LEFT JOIN auctions ON auctions.product_id=products.id WHERE auctions.id = $auctionid", $holder); // PROBABLY NEED TO FIX THIS // Need to get ALL of the email addresses who have ANY of the above auction ids on their watchlist // $email = mysql_query("SELECT email FROM users LEFT JOIN watchlists ON users.id=watchlists.user_id WHERE watchlists.auction_id = $auctionid", $holder); // Update the auctions table. Turn notification to 1 so the notification for that auction can't be sent again // AGAIN NEED THIS FOR ALL OF THE AUCTIONS ENDING IN 3 HOURS // $query1="UPDATE auctions SET notification = '1' WHERE id = '$auctionid'"; mysql_query($query1) or die(mysql_error()); $mail = new PHPMailer(); $mail->From = "no-reply@domain.com"; $mail->FromName = "Site Name"; // Getting and error message for the foreach but I saw a similar example and this is what I was told to do // NEED THIS TO ADD EACH OF THE EMAIL ADDRESSES INDIVIDUALLY // foreach ( $email as $recipients ) { $mail->AddAddress ($recipients); } $mail->WordWrap = 50; // set word wrap to 50 characters $mail->IsHTML(true); // set email format to HTML $mail->Subject = "Your Watched Auction is Ending Soon"; // Sample Body // WANT TO DISPLAY THE TITLE OF THE AUCTION (NAME OF PRODUCT) FOR THE AUCTION ID USING $auctiontile FROM ABOVE // $mail->Body = "Your auction titled $auctiontile is ending soon"; // Same as above // $mail->AltBody = Your auction titled $auctiontile is ending soon"; if(!$mail->Send()) { echo "Message could not be sent."; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "Message has been sent"; ?> Need some feedback on this loop Tables: Table A Table B Loop Select all from A based on criteria a. Insert into table B using row data from table A b. Update record in table A to say that it has gone through loop to prevent future loop Thats three MySQL queries running over and over at the same time, how bad is that for performance, is there another way? Maybe instead of running b each time build an array with the record ids from Table A and after the loop runs to insert into Table B run another query with the IN command to loop through all of the IDs in the array and update? Hi, this is my first post:) pretty sure i will be posting here in the future. Anyway i am having trouble with a php script which downloads a file from a mysql database. This php script works for text files and should work for most files from what i understand. When downloading a text file, the whole file is downloaded from the server. When downloading an mp3 file, only 16kb are downloaded and the file does not play. When looking at the data in the database, it displays that the full file is there (correct amount of bytes, so there is nothing wrong with my upload php script). Does anyone have any suggestions as to what I can change to make this work? Code: [Select] <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database $link=mysql_connect('localhost', 'root', ''); @mysql_select_db('filemgr') or die ("<p>Could not connect to mysql!</p>"); $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type:$type"); header("Content-Disposition: attachment; filename=$name"); echo $content; mysql_close($link); exit; } ?> I made a script to send 10 emails every 30 seconds to different recipients, but sometimes it fails, stops while sending, doesn't send all... Code: [Select] <?php include('config.php'); $getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'"; $getUser_not_sent = mysql_query($getUser_sql_not_sent); $i = 0; while ($row = mysql_fetch_array($getUser_not_sent)) { $emailUser = $row['email']; $emailFrom = "from@from.com"; $emailSubject = 'subject'; $emailVerify = "url.php?email=" . $emailUser; $emailBody = "<a href = \"$emailVerify\">link</a>"; $emailHeaders = "From:" . $emailFrom ."\r\n"; $emailHeaders .= "MIME-Version: 1.0\r\n"; $emailHeaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $emailHeaders .= "X-Priority: 3\r\n"; if (mail($emailUser, $emailSubject, $emailBody, $emailHeaders)) { mysql_query("UPDATE emails SET sent = '1' WHERE email = '$emailUser'") or die (mysql_error()); $i++; } if ($i == 10) { sleep(30); $i = 0; } } exit; ?> What should I change? Hello, Im using a wordpress blog which has links to filesonic i want to be able to mass update all the links to another host, Ive made a script that will do it for a single link but i can't think how to get it to do it for more than 1 link in the post. sometimes there are files like 1211.part1.rar 1211.part2.rar, It updates the part1 fine but dosen't update part 2. Any ideas how i can alter my script to replace the part2 files aswell? Code: [Select] <?php if($_POST[newlinks]) { $query = "SELECT * FROM wp_posts WHERE post_status = 'publish'"; $result = mysql_query($query); while($row=mysql_fetch_assoc($result)) { $find = $row['post_content']; preg_match("/http:\/\/www.filesonic.com\/file\/(.*?)\/(.*?).rar/", $find, $matches); $newlinks = preg_split('~\s+~s', $_POST['newlinks']); rtrim($newlinks, "\n\t\r"); foreach ($newlinks as $newlink) { $new_number = explode('/', $newlink); $new_number = end($new_number); $new_number = str_replace(".rar", "", "$new_number"); if($matches[2] == $new_number && isset($newlink) && strlen($newlink) > 1) { $newsql = preg_replace("/http:\/\/www.filesonic.com\/file\/(.*?)\/(.*?).rar/", $newlink, $find); $updatesql = "UPDATE wp_posts SET post_content = '$newsql' WHERE ID = '$row[ID]'"; if(mysql_query($updatesql) or die(mysql_error())) { echo "Success! Replaced http://www.filesonic.com/".$matches[1]."/".$matches[2].".rar with $newlink ID: $row[ID]<br />"; } } } } } else { echo "<form method=\"POST\" action=\"update-links.php\">"; echo "<br /> <strong>Enter the new links to try and replace old ones</strong> <br />"; echo "<textarea rows=\"16\" name=\"newlinks\" cols=\"84\"></textarea>"; echo "<input type=\"submit\" value=\"Submit\" name=\B1\">"; } ?> Hello, I found some little php code to check google index of any site. Code: [Select] <?php function checkSite($www) { $ch = curl_init('http://www.google.pl/search?hl=pl&q=site%3A'.trim($www).'&btnG=Szukaj&source=hp'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $sHtml = curl_exec($ch); preg_match('#\<div id=resultStats\>.*([0-9,]+) wynik#Ui', $sHtml, $aMatches); curl_close($ch); return (int)str_replace(',', '', $aMatches[1]); } echo checkSite('domain.com'); ?> But to check any site I must edit this code and add new site manually. I'm big beginner in PHP. I want to have a area on browser side to add many sites, and receive result, like in this code which I add. above. Can anybody help me with this? PS. Sorry for my poor English. Hey.
Got a slight issue, originally occured during the NodeJS version of the application, but it's also existing in the PHP version. (Yes, I have two versions, I know it's stupid)
The issue at hand is that I've got a Script that calls an API for data around 5 times each time the script is executed. So imagine http://Mywebsite/mypath/generate
public function doGenerate() { $restRequestHelper = new RestRequestHelper(...); $data1 = $restRequestHelper->fetch(...); ... ... $data5 = $restRequestHelper->fetch(...); }As you can imagine it hits a bit on the API's CPU since there's a lot of concurrent requests involving database operations. I know it's inevitable to optimize the API as well, but first I want to solve the client side of things, namely the mass refresh issue. If a Client has entered /generate/ and starts refreshing the page over and over again (or a Client just sending GET requests), the script keeps going for however many times they've refreshed and eventually the API will crash. You can think of it as a DOS attack, sort of. In the PHP version it's not nearly as harsh, but still harsh. It will keep doing it X amount of times and eventually show the response on the last request in the loop. In the NodeJS version, it's way worse. It's way faster, resulting in more concurrent requests on the API, making it crash faster. Same reason here, the spam. Anyone got a good way of blocking this kind of behavior of the client? PHP or NodeJS solutions will help. Think of the problem like this: $requestCount = 0; while($requestCount < 20) { $data1 = $restRequestHelper->fetch(...); $data2 = $restRequestHelper->fetch(...); $data3 = $restRequestHelper->fetch(...); $data4 = $restRequestHelper->fetch(...); $data5 = $restRequestHelper->fetch(...); $requestCount++; } Edited by Alex_, 13 November 2014 - 12:47 PM. Hi I need to send out +- 10 000 statements to our customers. How do I prevent from being marked as a spammer? I think the daily limit is 500. Should I use a public smtp? Thanks Jay I have some code which i think is really inefficient especially as there will be more more conditions to be met. I was thinking about using s switch but don't know if this is possible or if it's best leaving as it is. Any ideas? if($parts[($i-1)]=="forum") { //do some code } else if($parts[($i-2)]=="forum") { //do code } else if (($parts[($i-1)]=="list-messages") && (isset($parts[($i+1)]))) { //do code } else { // do some code } this xml_parse_into_struct($iP=xml_parser_create(), curl_exec($ch), $bR, $bJ);xml_parser_free($iP); echo "::: ".strip_tags(str_replace("<br>","\n",$bR[$bJ['MESSAGE'][0]]['value']))."\n"; or... $xml = simplexml_load_string(curl_exec($ch)); foreach($xml->xml as $message){ echo strip_tags($message->message)."\n";} Just want to know which of these two would execute faster and if there was a better way that would be faster than both of these options? Thanks Code: [Select] <?php $IPaddress = $_SERVER['REMOTE_ADDR']; if(stristr($IPaddress, "123.456.58.451") || stristr($IPaddress, "123.126.456.10") || stristr($IPaddress, "123.126.456.10")) { echo "<center><b><i>CWB permits you to views this page...</i></b></center></br>"; echo '<center><b><font size="5">'.$IPaddress.'</font></b></center>'; } else { echo "<center><b>CWB DOES NOT PERMIT YOU TO VIEW THIS PAGE</b></center>"; } exit; ?> how do I make it to where I dont have to keep adding on to Code: [Select] if(stristr($IPaddress, "123.456.58.451") || stristr($IPaddress, "123.126.456.10") || stristr($IPaddress, "123.126.456.10")) Okay so i have an image gallery script that creates two links, "Next Image" and "Previous Image". The script works but i'd like to know if i could make it more efficent with a better SQL query. Here's my database What i am currently doing is querying the database and getting a list of all the image id's in the same gallery, and putting them into an array. Which doesn't seem very logical (but it's the only solution i could come up with). Code: [Select] // CREATE AN ARRAY WITH ALL THE IMAGE ID'S IN THE GALLERY // $query = ("SELECT id FROM images WHERE gallery_id=(SELECT gallery_id FROM images WHERE id='".$_REQUEST['id']."') ORDER BY id DESC"); $result = mysql_query($query); $images_in_gallery = array(); while ($row = mysql_fetch_array($result)) { array_push($images_in_gallery, $row['id']); } And then searching through said the array to get the id of the next image and the previous image. Code: [Select] // CREATE THE LINK // $next_link = "<a href=\"?id=".$images_in_gallery[array_search($_REQUEST['id'], $images_in_gallery)+1]."\">$next_text</a>"; $prev_link = "<a href=\"?id=".$images_in_gallery[array_search($_REQUEST['id'], $images_in_gallery)-1]."\">$prev_text</a>"; Is there a way i can do this easier with a better query, for example a query that selects the next image in the gallery and the previous, i am not brilliant with SQL but i do know that if you have a good query your code can be considerably shorter. The full code can be found here on pastebin. http://pastebin.com/GzTpq6Uj Hello, I'm new to PHP and I have come up with the following code for my navigation but I am sure there has to be an easier and more efficient way to do this. Someone please start me on the right path. Thanks Code: [Select] <?php //Get selected page/sub page if (isset($_GET['page'])) { $sel_page = $_GET['page']; $sel_sub_page = ''; } elseif (isset($_GET['sub_page'])) { $sel_page = ''; $sel_sub_page = $_GET['sub_page']; } else { $sel_page = ''; $sel_sub_page = ''; } ?> Code: [Select] <!--Begin Navigation--> <ul> <?php //run the loop to get the page titles $query = "SELECT * FROM pages ORDER BY position ASC"; $page_set = mysql_query($query); confirm_query($page_set); while($page = mysql_fetch_array($page_set)){ echo '<li><a href="content.php?page=' . urlencode($page['id']) . '">' . $page['page_name'] . '</a></li>'; //run sub page query to see if the ul tag is needed $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); $sub_page = mysql_fetch_array($sub_page_set); if ($sub_page !=''){ echo '<ul>'; } //run the sub page loop again to display the sub page title $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); while($sub_page = mysql_fetch_array($sub_page_set)) { echo '<li><a href="content.php?sub_page=' . urlencode($sub_page['id']) . '">' . $sub_page['page_name'] . '</a></li>'; } //run the sub page loop for the last time to see if the end ul tag is needed $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); $sub_page = mysql_fetch_array($sub_page_set); if ($sub_page !='') { echo '</ul>'; } } ?> </ul> <!--End Navigation--> Hi all! I'm a real noob and this is my first time making a website and I haven't hosted it yet. I'm trying to make a website that is fast and secure. My pages look something like this. Code: [Select] <?php include("header.php");include("sidebar.php"); ?> HTML CODES <?php include("footer.php"); ?> 1. Are these php files cached after their first load? When I go to another page, those parts seem to stay still. 2. Is this code secure? And now I'm starting to make product pages which will be around 40 pages. So I'm considering something like this... Code: [Select] <?php include("header.php");include("sidebar.php"); ?> <a href="index.php?page=a">Page A</a> <?php $page = $_GET['page']; if (file_exists('pages/'.$page.'.php')) { include('pages/'.$page.'.php'); } ?> <?php include("footer.php"); ?> 3. Is it better to make every page like this since it will load header, sidebar, footer only once? 4. How should I protect from the user input data, by making an array of allowed files or by prohibiting "." and "/" ? Thank you in advance. Hi guys, I want to find the most efficient way of setting a php variable through a link.
What I'm trying to achieve is to allow the user to select a category and their location and store the two variables to update my database results. I first used the GET method, but since the page refreshes when the user selects any other Get variable, so it ends up reseting the variables. Currently I have the category and locations as drop down menu with links to each of the options. I'll appreciate any help. Thank you. :]
$ch = curl_init(); //////////////////////////////////// //////////////////////////////////// for($cwb=1; $cwb!=$Amount; $cwb++) { $action = file_get_contents($Game."refresh_stat_manual?user_id=".$Keys[0]."&auth_key=".$Keys[1]); $xml = simplexml_load_string($action); foreach($xml->xml->viewer->user as $stats) { $energy=$stats->energy; $level=$stats->level; } if($energy <= 0 || $Stop <= $level) { echo "REACHED EITHER LEVEL $Stop OR... YOU ARE OUT OF ENERGY...\n"; sleep(100000); } $send1 = $Game."send_requests?user_id=".$IDone."&to_user_ids=".$Keys[0]."&auth_key=".$AuthOne; curl_setopt($ch, CURLOPT_URL, $send1); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $send2 = $Game."send_requests?user_id=".$IDtwo."&to_user_ids=".$Keys[0]."&auth_key=".$AuthTwo; curl_setopt($ch, CURLOPT_URL, $send2); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $accept = $Game."accept_all_mob_requests?user_id=".$Keys[0]."&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $accept); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $job = $Game."do_job?user_id=".$Keys[0]."&job_id=7200018&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $job); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $exec1 = curl_exec($ch); if(stristr($exec1, 'You gained 6') || stristr($exec1, 'You gained 1') || stristr($exec1, 'ambulance')) { echo "#$cwb: <-- You've gained 1 ambulance... Level - ".$level." ::: ENERGY - ".$energy." :::\n"; } for($abc =1; $abc!=2; $abc++){ $remove1 = $Game."remove_mob_member?user_id=".$Keys[0]."&remove_user_id=".$IDone."&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $remove1); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);} for($abc =1; $abc!=2; $abc++){ $remove2 = $Game."remove_mob_member?user_id=".$Keys[0]."&remove_user_id=".$IDtwo."&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $remove2); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);} $sell = $Game."buy_item?user_id=".$Keys[0]."&item_id=32&amount=".$Amount."&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $sell); $exec2 = curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if(stristr($exec2, 'sold')) { echo "::: You've sold 1 ambulance...\n"; } } curl_close(); Any idea on how I could make this faster or what I could change to make it to more efficient Hi all, I've been trying to improve the speed of my file download script and was wondering if anyone could advise me which of the following is more efficient (Don't worry its not the whole script, just one segment), in terms of speed and server load? The way I have the segment currently: //if file exists need to check authorision levels //set access to no $access = NULL; //retrieve current user levels $cpm = $_SESSION['MM_CPMGroup']; $cpmh = $_SESSION['MM_CPMHGroup']; $cm = $_SESSION['MM_CMGroup']; $cj200 = $_SESSION['MM_CJ200Group']; $cj = $_SESSION['MM_CJGroup']; //set file category type & set access if allowed if ($category == 'cpm') { if ($cpm == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cpm/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cpm/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cpm/"; } else { $path = "files/cpm/"; } } } elseif ($category == 'cpmh') { if ($cpmh == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cpmh/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cpmh/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cpmh/"; } else { $path = "files/cpmh/"; } } } elseif ($category == 'cm') { if ($cm == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cm/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cm/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cm/"; } else { $path = "files/cm/"; } } } elseif ($category == 'cj200') { if ($cj200 == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cj200/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cj200/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cj200/"; } else { $path = "files/cj200/"; } } } elseif ($category == 'cj') { if ($cj == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cj/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cj/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cj/"; } else { $path = "files/cj/"; } } } if ($access < 1) { // if user access not granted to file category return message if($logging > 0){ $status = "Wrong Permissions"; include('logit.php'); } if (! $_SESSION['PrevUrl']) { //header("Location: ". $loginpage ); exit; } $redirect = $_SESSION['PrevUrl']; header("Location: ". $redirect ); exit; } // if file exists and user access granted continue Obviously the above is a lot of lines of code... So I have rewritten the above to look like: //if file exists need to check authorision levels & retrieve current user levels if ($category == 'cpm' && $_SESSION['MM_CPMGroup'] == '1') { $access = 1; } elseif ($category == 'cpmh' && $cpmh = $_SESSION['MM_CPMHGroup'] == '1') { $access = 1; } elseif ($category == 'cm' && $cm = $_SESSION['MM_CMGroup'] == '1') { $access = 1; } elseif ($category == 'cj200' && $_SESSION['MM_CJ200Group'] == '1') { $access = 1; } elseif ($category == 'cj' && $_SESSION['MM_CJGroup'] == '1') { $access = 1; } else { $access = NULL; } if ($access == NULL) { // if user access not granted to file category return message $status = "Unauthorised"; include('logit.php'); header("Location: ".$_SESSION['PrevUrl']); exit; } // if file exists and user access granted continue switch($subcategory) { case "techdata":$path="files/techdata/".$category."/".$filename; break; case "msds": $path="files/techdata/".$category."/msds/".$filename; break; case "symbols": $path="files/symbols/".$category."/".$filename; break; default: $path="files/".$category."/".$filename; } The second version is a lot shorter, but is it better? And could I shorten the if statement further so its more like: //if file exists need to check authorision levels & retrieve current user levels if (($category == 'cpm' && $_SESSION['MM_CPMGroup'] == '1') || ($category == 'cpmh' && $cpmh = $_SESSION['MM_CPMHGroup'] == '1') || ($category == 'cm' && $cm = $_SESSION['MM_CMGroup'] == '1') || ($category == 'cj200' && $_SESSION['MM_CJ200Group'] == '1') || ($category == 'cj' && $_SESSION['MM_CJGroup'] == '1') { $access = 1; } else { $access = NULL; } if ($access == NULL) { // if user access not granted to file category return message $status = "Unauthorised"; include('logit.php'); header("Location: ".$_SESSION['PrevUrl']); exit; } // if file exists and user access granted continue switch($subcategory) { case "techdata":$path="files/techdata/".$category."/".$filename; break; case "msds": $path="files/techdata/".$category."/msds/".$filename; break; case "symbols": $path="files/symbols/".$category."/".$filename; break; default: $path="files/".$category."/".$filename; } Any advice would be appreciated! Thanks!! |