Welcome to WebmasterWorld Guest from 54.166.117.130

Forum Moderators: coopster & jatar k

mysql connect or die (image) header type png

   
2:37 pm on Mar 1, 2008 (gmt 0)

5+ Year Member



im looking to achieve something like this

mysql_connect($mysql_server, $mysql_admin, $mysql_pass) or die("<img src='http://site.com/error.png'>");

BUT it doesnt render properly in the browser, unless you click the link

i need to include

// Create: HEADERS //
header("Content-type: image/png");
header ("Cache-Control: max-age=7200")

within the DIE command or something, so the browser will take it as an image

2:43 pm on Mar 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do you mean by 'it doesn't render properly'? What exactly happens?

It should work fine as you have it.

2:49 pm on Mar 1, 2008 (gmt 0)

5+ Year Member



no its a dynamic image script, and to fetch it i use

'<a href="http://site.com/script.php?name=' . $profile['user'] . '" target="_blank"><img src="http://site.com/script.php?name=' . $profile['user'] . '" alt="' . $profile['user'] . '" border="0" /></a>',

now if this user exists, it LOADS fine, but if it cant connect to mysql server, it gives the DIE, and SHOWS THE ALT text, the headers dont get sent during the die command it shows the ALT text, when it LOADS fine it sends the headers cause headers are at the end of the script

2:50 pm on Mar 1, 2008 (gmt 0)

5+ Year Member



i want on DIE to print an "unavailable" image, but within the die command the headers arent sent and it doesnt know its an image
3:07 pm on Mar 1, 2008 (gmt 0)

5+ Year Member



the script has // Create: HEADERS //
header("Content-type: image/png");
header ("Cache-Control: max-age=7200");
//header ("Pragma: no-cache");
putenv('GDFONTPATH=' . realpath('.'));

// PINGS //

ImagePng($image);
ImageDestroy($image);

at the end, the beginning is mysql_connect($mysql_server, $mysql_admin, $mysql_pass) or die("<img src='http://site.com/error.png'>");

i want to show an unavailable.png image, but instead im left with the ALT text from <a href="http://site.com/script.php?name=' . $profile['user'] . '" target="_blank"><img src="http://site.com/script.php?name=' . $profile['user'] . '" alt="' . $profile['user'] . '" border="0" /></a>',

something isnt getting passed in the die command

4:01 pm on Mar 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I think I see what's happening. Since you have already sent the headers, you should just output the raw image instead of putting it in an HTML image tag.

mysql_connect($mysql_server, $mysql_admin, $mysql_pass)
or die( readfile( 'error.png' ) );

3:25 am on Mar 2, 2008 (gmt 0)

5+ Year Member



that got it thank you
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month