Jump to content

Output "legit" error messages


Kairu

Recommended Posts

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]<?php

function 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?
Link to comment
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.