Jump to content
xisto Community
Sign in to follow this  
AlternativeNick

Url_exists

Recommended Posts

i found this on php.net, and it worked for a little while, and now it doesnt work.

i changed some of it trying to fix it, but it always returns false.

function url_exists($url){	  if(!strstr($url, "http://")) { $url = "http://".$url; };   $fp = @fsockopen($url, 80);   if($fp === false) { return 'false'; } else { return true; };};

Edited by AlternativeNick (see edit history)

Share this post


Link to post
Share on other sites

i found this on php.net, and it worked for a little while, and now it doesnt work.
i changed some of it trying to fix it, but it always returns false.

function url_exists($url){	  if(!strstr($url, "http://")) { $url = "http://".$url; };   $fp = @fsockopen($url, 80);   if($fp === false) { return 'false'; } else { return true; };};
I'm not sure, but perhaps the last line of code with the "$fp === false" is the problem. Shouldn't that be "$fp == false"?

Share this post


Link to post
Share on other sites
function url_exists($url){if(!strstr($url, "http://")) { $url = "http://".$url; };$fp = @fsockopen($url, 80);if($fp === false) { return 'false'; } else { return true; };};
Right here goes. You are returning the text "false" and not just false, so that's problem one. Another problem I spotted was that you put a ";" after the "}", and you do not do that. So here is the code fixed:
function url_exists($url){if(!strstr($url, "http://")) { $url = "http://".$url; }$fp = @fsockopen($url, 80);if($fp === false) { return false; } else { return true; }}

And I believe it isn't to do with the ===, as that means if it returns something (I think).

Share this post


Link to post
Share on other sites

I'm not sure, but perhaps the last line of code with the "$fp === false" is the problem. Shouldn't that be "$fp == false"?

Should still work the same way

And I believe it isn't to do with the ===, as that means if it returns something (I think).

'===' means exact equivalence instead of just equivalence. Example:

if(false==0)//returns true
if(false===0)//returns false

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.