Forum Moderators: coopster

Message Too Old, No Replies

what if file get contents is an image?

         

Seamless

9:32 pm on Nov 11, 2008 (gmt 0)

10+ Year Member



Hi,

I wonder if anyone can help me. The users on my site are allowing me to show other users their MSN messenger status (whether it be offline, online etc).

I would like to put people that are online on MSN messenger in a seperate list using MySQL.

I know the url that I should checking for their status and MSN returns an image.

I would like a way via PHP to:


if($msn_return == ""){
// change status in db here
}

but how do you check if a variable equals an actual image rather than a value.

if i echo $msn_return all i get is a load of symbols which i guess is the text version of the image.

Any help would be much apreciated.

Thanks

Seamless.

brotherhood of LAN

9:42 pm on Nov 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I know the url that I should checking for their status and MSN returns an image.

You might want to perform a regex on where you expect to see the image, and see whether it's the 'online' or 'offline' image.

/edited
I meant in the sense of viewing a 'profile', but since you're viewing simple a returned image file, perhaps there is something in the heads that indicate whether it's the online or offline image, i.e. filesize

otherwise you could do an MD5 of the image file, it should return two values

[edited by: brotherhood_of_LAN at 9:43 pm (utc) on Nov. 11, 2008]

Seamless

9:49 pm on Nov 11, 2008 (gmt 0)

10+ Year Member



thanks for the quick reply...

could you give me an example of how to go about doing one of the methods you mentioned?

Thanks

brotherhood of LAN

10:08 pm on Nov 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sure

You might want to look into using cURL [uk2.php.net] for URL fetching as it's rich in customisation and will allow you to make HTTP/1.1 and HEAD only requests.

Otherwise something like this:

echo md5(file_get_contents($url))

I'm thinking you should get 2 MD5's returned, one for the online image and one for the offline one.

Seamless

10:19 pm on Nov 11, 2008 (gmt 0)

10+ Year Member



Thanks, i'll give both methods a try :)

Seamless

Seamless

10:51 pm on Nov 11, 2008 (gmt 0)

10+ Year Member



Yayy!

I was able to determine the different md5 values for the different status' and use that.


function msn_status($msn){
$offline_status = array("ae1daee572ed6b1e8d19e27a70bcc676",
"20babb80e0a673174d8ecd538f173066",
"ae1daee572ed6b1e8d19e27a70bcc676",
"8a485b75acb289c87f4a2d94867338c9");
$online_status = array("1655410ae3015b6b1df7543e8357001b",
"b938fb7ad566838506defcf7af075d68",
"13ac99d606d9c30a4b8226cd47164f1b",
"73c4845f0b1bfe095224ccfcb415f8ed",
"5a144da553be66596505a92428dbf518",
"b938fb7ad566838506defcf7af075d68",
"cc97d7a872731601945917fd6b6a927a",
"73c4845f0b1bfe095224ccfcb415f8ed",
"be168b5c4e424b55c3961f1410d6e7f2",
"449085118397a452cb91c8e2e3b7a2e6",
"8ffbeb473e9e1b28efc14aafc2e57f2d",
"b938fb7ad566838506defcf7af075d68",
"c0da67babe50fefeb151b3f92c4e7c0c");
$url = "http://messenger.services.live.com/users/".$msn."/presenceimage?mkt=en-GB";
$md5 = md5(file_get_contents($url));
if(in_array($md5,$online_status)){
return 1;
}elseif(in_array($md5,$offline_status)){
return 0;
}else{
return 0;
}
}

Thanks very much for your help!

Seamless

brotherhood of LAN

8:25 am on Nov 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Were there more than two?

I'd have thought there'd only be two images, 'online' and 'offline'

As I say, check out cURL. If you can distinguish between them just by using the HTTP Headers, that'd be much more efficient in the long run.

Seamless

8:44 am on Nov 12, 2008 (gmt 0)

10+ Year Member



Yes there are more than 2.

2x Offline (gif/png)
2x Appear Offline (gif/png)

Then there are icons for idle, busy which i have classed as online anyway.

Infact looking back i see that i have a couple of duplicates.

I will look into cURL

Thanks

Seamless