Check if link exists

Need some coding help with a MOD or tweak you are working on? - Ask here.
Forum rules
Ask for support specifically regarding coding help with phpBB3.
Not for generic usability questions or support.

Check if link exists

Postby wadie » 16 Jan 2012, 09:25

Function I have (in includes/functions_posting.php):

Code: Select all
function url_exists($url) {
$handle = @fopen($url, "r");
if ($handle === false){
return false;
fclose($handle);
}
else{
return true;
fclose($handle);
}
}


Usage (In posting.php):
Code: Select all
$your_url = "http://www.somewhere.com/index.php";

$your_url = preg_replace(array('#&\#46;#','#&\#58;#','/\[(.*?)\]/'), array('.',':',''), $your_url);

if (url_exists($your_url))
{
echo 'yeah, its reachable';
}
else
{
echo 'what da hell..';
}


I think it works just fine. I get the text echoed on header with an error saying headers already sent.
Instead of echo I now use trigger_error('error message);
Now I get the error the way I want it to be,except that no matter what the url I have in $your_url I keep getting the same error that the URL exists even when it's not!

Also,I'd like to make the function work after I click submit topic and not when I click create new topic.

Thanks. :)
PM me for private support or installing MODs/styles.
User avatar
wadie    
Lieutenant
Lieutenant
 
Posts: 329
Joined: 11 Mar 2010, 10:14
Gender: Male
phpBB Knowledge: 5


Re: Check if link exists

Postby Obsidian » 16 Jan 2012, 19:23

A: your code will not work if the page "exists" but the server returns HTTP 404 or another "invalid page" status message.

B: use the template system.
うるさいうるさいうるさい!

StopForumSpam Spam Reporting Database
Giving xrumer and friends a great big "screw you" since 2007.
User avatar
Obsidian    
Supporter
Supporter
 
Posts: 2250
Joined: 04 Mar 2008, 23:35
Gender: Male
phpBB Knowledge: 10

Re: Check if link exists

Postby wadie » 17 Jan 2012, 07:04

So what code changes should I make ? :O
PM me for private support or installing MODs/styles.
User avatar
wadie    
Lieutenant
Lieutenant
 
Posts: 329
Joined: 11 Mar 2010, 10:14
Gender: Male
phpBB Knowledge: 5

Re: Check if link exists

Postby wadie » 28 Jan 2012, 10:49

I figured that part out. now I'm having a different issue..

It doesn't matter what's the full URL. it's enough to assign http://www. to the variable
Code: Select all
$post_data['your_url']

and then it will always show that the url exists no matter what's the url I'm trying to post.

I'd really appreciate some help! :)
PM me for private support or installing MODs/styles.
User avatar
wadie    
Lieutenant
Lieutenant
 
Posts: 329
Joined: 11 Mar 2010, 10:14
Gender: Male
phpBB Knowledge: 5

Re: Check if link exists

Postby Handyman » 24 Apr 2012, 15:09

Did you get this one figured out?
Please contact me if you have any news to submit to SCOFF News.
SCOFFing at the candidates while you sleep.
My Mods || My Mod Queue
Image
User avatar
Handyman    
Rear Fleet Admiral
Rear Fleet Admiral
 
Posts: 7456
Joined: 08 May 2006, 04:45
Location: Where no man has gone before!
Favorite Team: Seattle Seahawks
Gender: Male


Return to phpBB3 Coding Assistance

Who is online

Users browsing this forum: No registered users and 12 guests