Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Url_exists
AlternativeNick
post Feb 2 2007, 05:52 PM
Post #1


Super Member
*********

Group: Members
Posts: 210
Joined: 7-June 06
Member No.: 24,817



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; };
};


This post has been edited by AlternativeNick: Feb 2 2007, 05:53 PM
Go to the top of the page
 
+Quote Post
Avalon
post Feb 3 2007, 11:31 AM
Post #2


Privileged Member
*********

Group: Members
Posts: 630
Joined: 12-August 05
From: Melbourne, Australia
Member No.: 10,624



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"?
Go to the top of the page
 
+Quote Post
QuickSilva
post Feb 3 2007, 12:05 PM
Post #3


Premium Member
********

Group: Members
Posts: 181
Joined: 15-January 07
From: Rotherham, UK
Member No.: 37,245



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).
Go to the top of the page
 
+Quote Post
galexcd
post Feb 3 2007, 10:22 PM
Post #4


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********

Group: [HOSTED]
Posts: 1,069
Joined: 25-September 05
From: L.A.
Member No.: 12,251



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Soldier Gets 100 Years In Prison For Raping An Iraqi Girl(28)
  2. Google Tv Exists And How To Invite Yourself!(9)


 



- Lo-Fi Version Time is now: 7th October 2008 - 12:24 AM