lynxus Posted May 29, 2009 Share Posted May 29, 2009 Hi guys, Me again Does anyone know how to do a dynamic image like: on my website i would insert a image that points to , blaaa.blaa.com/status.php?id=1234567890 Then depending on teh output of the php file, it would display online or offline. I suppose i would just want the php file to say use this image or this image. Any ideas? Thanks G Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/ Share on other sites More sharing options...
Zhadus Posted May 29, 2009 Share Posted May 29, 2009 If (condition1) echo '<img src="1.jpg" />'; else echo '<igm src="2.jpg" />'; Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845037 Share on other sites More sharing options...
lynxus Posted May 29, 2009 Author Share Posted May 29, 2009 Yeah that doesn't work. On my page is html.. Like : <img src="http://site.com/status/status.php" /> I want that to display an image based on the php. Either a user is online or offline. Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845065 Share on other sites More sharing options...
kickstart Posted May 29, 2009 Share Posted May 29, 2009 Hi You can generate an image in php and stream that out. Check the imagecreate function in the php documentation. There is a simple example there. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845067 Share on other sites More sharing options...
laffin Posted May 29, 2009 Share Posted May 29, 2009 On/Off Status images usually require information on getting the status of the user. U may want to check ICQ/MSN/AIM/Yahoo protocols. or create yer own client to pass info to a page (Like some DynDNS clients do, to get an updated ip address) Once ya got the method of On/Off Detection, than its just a matter of following post #2 in this thread. There is no real magic to this, just some thought beforehand Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845230 Share on other sites More sharing options...
lynxus Posted May 30, 2009 Author Share Posted May 30, 2009 Post 2 doesnt work. I already have teh condition. $status = either 1 or 0 it returns correctly but the images dont work If in a html page i refer to the php file instead of blaa.png nothing happens. Ie: test.php <?php $status = "1"; If ($status == "1"){ echo '<img src="http://blaaaaa.com/1.png" />'; }else{ echo '<igm src="http://blaaaaa.com/2.png" />'; } ?> Then if in a html file i refer to test.php instead of 1.png nothing happens. Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845602 Share on other sites More sharing options...
Garethp Posted May 30, 2009 Share Posted May 30, 2009 Status.php should be something like <?php // tell the user's browser that it is an image header("Content-type: image/png"); if($Status == "Offline") { $image = imagecreatefrompng("Offline.png"); } else { $image = imagecreatefrompng("Online.png"); } // and now... we display the image imagepng($image); imagedestroy($image); ?> Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845604 Share on other sites More sharing options...
phpdragon Posted May 30, 2009 Share Posted May 30, 2009 what does the resulting html source look like when you have tested each condition, and are both images in the location you have specified and the paths correct? If you have already determined that a user is online/offline by by declaring a variable as 1 or 0 then displaying an image would be easy. Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845605 Share on other sites More sharing options...
Garethp Posted May 30, 2009 Share Posted May 30, 2009 The problem with using <?php $status = "1"; If ($status == "1"){ echo '<img src="http://blaaaaa.com/1.png" />'; }else{ echo '<igm src="http://blaaaaa.com/2.png" />'; } ?> And then using that as an image source, is that the above code is outputting in HTML format, not image format Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845606 Share on other sites More sharing options...
Axeia Posted May 30, 2009 Share Posted May 30, 2009 ummm spelling error? igm is not an existing tag, img is though. Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845618 Share on other sites More sharing options...
lynxus Posted May 30, 2009 Author Share Posted May 30, 2009 Hi Garethp. Your code works perfectly! Awesome! Cheers _G Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845656 Share on other sites More sharing options...
Garethp Posted May 30, 2009 Share Posted May 30, 2009 Glad to be of service Quote Link to comment https://forums.phpfreaks.com/topic/160160-solved-online-offline-dynamic-image/#findComment-845658 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.