Jul 25, 2008

Url_exists

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Url_exists

AlternativeNick
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.

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

Reply

Avalon
QUOTE(AlternativeNick @ Feb 3 2007, 04:52 AM) *
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.

CODE
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"?

 

 

 


Reply

QuickSilva
CODE
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:
CODE
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).

Reply

galexcd
QUOTE(Avalon @ Feb 3 2007, 03:31 AM) *
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

QUOTE(QuickSilva @ Feb 3 2007, 04:05 AM) *
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:


Searching Video's for url, exists
advertisement



Url_exists



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE