Kairu Posted December 25, 2006 Share Posted December 25, 2006 Alright.... What I'm trying to do, (as some of you know by now, since I've been here for a week or so) is create an image dynamically with URL's and coordinates from a database.I have used a .htaccess file to all but hide the fact that it is PHP, and now need help in creating a legit 404 error (Meaning my server returns a "file not found" or other if the file is not called correctly.This is what I tried first, but it did not work, because I forgot to take into account that each browser has a different way of handling the error messages.[code]<?phpfunction hide(){ echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"; echo "<html><head>\n"; echo "<title>404 Not Found</title>\n"; echo "</head><body>\n"; echo "<h1>Not Found</h1>\n"; echo "<p>The requested URL " . $_SERVER['REQUEST_URI'] . " was not found on this server.</p>\n"; echo "</body></html>\n"; exit();}mysql_connect('localhost:3306', 'User', 'Pass');mysql_select_db('gaia_image');$result = mysql_query('SELECT * FROM data WHERE id = ' . $_GET['id']);$row = mysql_fetch_array($result);if ($row[0] == ""){ hide();}elseif(strpos($_SERVER['REQUEST_URI'], 'image.php') != FALSE){ hide();}elseif($_GET['ext'] == "jpeg" || $_GET['ext'] == "jpg"){ header('content-type: image/jpeg');}elseif($_GET['ext'] == "png"){ header('content-type: image/png');}elseif($_GET['ext'] == "gif"){ header('content-type: image/gif');}else{ hide();}$sig = $row[1];$n = $row[2];$image = array(); $avi = array(); $avi_width = array(); $avi_height = array(); $dest_x = array(); $dest_y = array(); $a = array();for ($i=0; $i<=$n; $i++){ array_push($a, $row[(($i * 3) + 3)]);}for ($i=0; $i<=$n-1; $i++){ array_push($avi, imagecreatefrompng($a[$i])); array_push($avi_width, imagesx($avi[$i])); array_push($avi_height, imagesy($avi[$i]));}array_push($image, imagecreatefromstring(file_get_contents($sig)));if ($row[33] != "1"){ array_push($image, imagecreatefromstring(file_get_contents($sig)));}$size = getimagesize($sig);for ($i=0; $i<=$n; $i++){ $temp = "\$temp = " . $row[(($i * 3) + 4)] . ";"; //Some of the rows that are called here eval($temp); //are actually formulas on how to get the array_push($dest_x , $temp ); //coordinates instead of exact coordinates, $temp = "\$temp = " . $row[(($i * 3) + 5)] . ";"; //so this is what I came up with to avoid eval($temp); //any problems that may arise. array_push($dest_y , $temp );}for ($i=0; $i<=$n-1; $i++){ imagecopy($image[0], $avi[$i], $dest_x[$i] , $dest_y[$i], 0, 0, $avi_width[$i], $avi_height[$i]); imagedestroy($avi[$i]);}if ($row[33] != "1"){ imagecopy($image[0], $image[1], 0, 0, 0, 0, $size[0], $size[1]); imagedestroy($image[1]);}if($_GET['ext'] == "jpeg" || $_GET['ext'] == "jpg"){ imagejpeg($image[0]);}elseif($_GET['ext'] == "png"){ imagepng($image[0]);}elseif($_GET['ext'] == "gif"){ imagegif($image[0]);}imagegif($image[0]);imagedestroy($image[0]);?>[/code](I am also open to suggestions on ways of "stream lining" my code)The file name is "image.php", but when it is called properly it is not. In essence what I am trying to do is remove all ways of figuring out if the file is php or a real image. Any suggestions off topic on how to do this are also welcome.Now to my question. Is there a way to mimic the results a server outputs when a file or folder is not found? Quote Link to comment Share on other sites More sharing options...
onlyican Posted December 25, 2006 Share Posted December 25, 2006 A legit 404 page you need to use the header() functionheader("HTTP/1.0 404 Not Found"); Quote Link to comment Share on other sites More sharing options...
Kairu Posted December 25, 2006 Author Share Posted December 25, 2006 Ah! It makes so much sense now!And should I leave the output text, or have it blank? Quote Link to comment Share on other sites More sharing options...
onlyican Posted December 27, 2006 Share Posted December 27, 2006 Servers have there own 404 pages (and other error codes)If you are using Linux Server, with CPanel, there is an option to edit the error pages Quote Link to comment Share on other sites More sharing options...
SharkBait Posted December 27, 2006 Share Posted December 27, 2006 In the apache config files, it will show/tell you where the 404 page as well as other pages are. I think they're just straight HTML pages. It's been a while since I looked at them. Quote Link to comment Share on other sites More sharing options...
onlyican Posted December 27, 2006 Share Posted December 27, 2006 On my server, in the website root folder (Where your website index file is)I have403.shtml404.shtmlBut it depends on what file the server looks for Quote Link to comment 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.