homepage Welcome to WebmasterWorld Guest from 54.242.126.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
mysql connect or die (image) header type png
Hitman3266

5+ Year Member



 
Msg#: 3588753 posted 2:37 pm on Mar 1, 2008 (gmt 0)

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

 

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3588753 posted 2:43 pm on Mar 1, 2008 (gmt 0)

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

It should work fine as you have it.

Hitman3266

5+ Year Member



 
Msg#: 3588753 posted 2:49 pm on Mar 1, 2008 (gmt 0)

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

Hitman3266

5+ Year Member



 
Msg#: 3588753 posted 2:50 pm on Mar 1, 2008 (gmt 0)

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

Hitman3266

5+ Year Member



 
Msg#: 3588753 posted 3:07 pm on Mar 1, 2008 (gmt 0)

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

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3588753 posted 4:01 pm on Mar 1, 2008 (gmt 0)

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' ) );

Hitman3266

5+ Year Member



 
Msg#: 3588753 posted 3:25 am on Mar 2, 2008 (gmt 0)

that got it thank you

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved