Jump to content


Photo
- - - - -

[PHP]URL Verification


  • Please log in to reply
13 replies to this topic

#1 sephet

sephet

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 07 August 2005 - 03:19 PM

URL Verification Tutorial

Written By Ben Kippax ::: http://www.layouts4u.co.uk :::


This tutorial will show you how to verify if a URL exists or if its a 404 error.



Step 1



<p><form action="verify.php" method="get">

URl (Don't include http://) <input type="text" name="url"><br/>

<input type="submit" value="send"><br/>
</form></p>



call this file "form_verify.php"



Step 2



<?
$up = @fsockopen("$url", 80, $errno, $errstr, 30);
if($up)
{
echo "$url Can Be found";
}
else
{
echo "<b>Oops! <br>$url Cant Be Found</b>";
}
?>


Call This file "verify.php"





Now, all you have to do is include form_verify.php in a page or keep it as a stand alone script and just link it. It's as simple as that.

For a working example please go to http://www.sephet.co...form_verify.php


I Hope you enjoy the tutorial.

Regards,
Ben

#2 brent

brent

    Young Padawan

  • Members
  • Pip
  • 72 posts
  • Location:Tennessee

Posted 07 August 2005 - 10:10 PM

can there be a way to check if they input the http:// part? just to make sure your visitors read directions...

#3 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 07 August 2005 - 10:22 PM

can there be a way to check if they input the http:// part? just to make sure your visitors read directions...

Replace Step 2 with this :)

<?
$url = $_POST['url'];

//REMOVE HTTP
$url = str_replace('http://', '', $_POST['url']);

$up = @fsockopen("$url", 80, $errno, $errstr, 30);
if($up)
{
echo "$url Can Be found";
}
else
{
echo "<b>Oops! <br>$url Cant Be Found</b>";
}
?>

Just in case a host has disabled REGISTER_GLOBALS, step two should originally be this:

<?

//DEFINE $URL
$url = $_POST['url'];

//GET RID OF THE HTTP
$url = str_replace('http://', '', $_POST['url']);

//TEST URL
$up = @fsockopen("$url", 80, $errno, $errstr, 30);

//IF URL FOUND
if($up)
{
echo "$url Can Be found";
}

//IF 404
else
{

//ECHO RESULTS
echo "<b>Oops! <br>$url Cant Be Found</b>";
}
?>

Edited by Jaymz, 07 August 2005 - 10:25 PM.


#4 brent

brent

    Young Padawan

  • Members
  • Pip
  • 72 posts
  • Location:Tennessee

Posted 08 August 2005 - 04:24 PM

ok, but shouldn't there be a way to test if they put in the http:// part or not? i'm sorry, just wondering....i'm going to be doing a link submission site/section soon and probably use this tut, plus others to help create this project...thanks for the help and reply

#5 sephet

sephet

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 08 August 2005 - 05:06 PM

ok i think this can be acheived using a simple "if" statement. Basically its what Jaymz said

$url = $_POST['url'];

$url = str_replace('http://', '', $_POST['url']);

that should be the first two lines of the code.

Really this is just saying that if the url contains http:// reaplace it with "nothing".

#6 HaloprO

HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 08 August 2005 - 06:11 PM

To determine wheather they entered http:// at the beginning you could use a simple regex
<?php
$search = "(http):\/\/(.*?)";
if (eregi($search, $_POST['url'])) {
   //success
} else {
  die('You did not enter http:// at the beginning of your url');
}
?>
The way sephet described all you would have to do is put http:// anywhere in the string, like www.google.com/http://
Would result www.google.com/

#7 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 08 August 2005 - 07:40 PM

The way I posted would eliminate http://'s anywhere, further securing the script from installing remote files on a server, as I have seen this done on my host and it's a pain in the butt.

#8 HaloprO

HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 08 August 2005 - 07:46 PM

I don't think that's what he wanted to do though, You could just have it disable the use of some extensions..Or display < and > so they can't use XSS, plus I messed up on my script up there, pm me and I'll give you one that works

#9 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 08 August 2005 - 07:56 PM

I don't think that's what he wanted to do though, You could just have it disable the use of some extensions..Or display < and > so they can't use XSS, plus I messed up on my script up there, pm me and I'll give you one that works

The way I posted would quietly get rid of the http:// if it existed, or continue on it's merry way :angry:

#10 HaloprO

HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 09 August 2005 - 02:04 AM

I know that...I'm not a noob, I just don't think he wants to get rid of it
EDIT: my bad he does want to get rid of it, sorry jaymz :)

Edited by HaloprO, 09 August 2005 - 02:09 AM.


#11 brent

brent

    Young Padawan

  • Members
  • Pip
  • 72 posts
  • Location:Tennessee

Posted 09 August 2005 - 09:32 AM

lol....yall are probably going to hate me....i was just wondering how to do it, not really wanting to take your code from you...hehe but thanks for all the info though...and sorry if it caused a little bickering.... :)

Edited by brent, 09 August 2005 - 09:32 AM.


#12 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 09 August 2005 - 10:07 AM

You can take my code, I made it for your needs :)

#13 sephet

sephet

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 09 August 2005 - 10:55 AM

that was a battle to explain that, lolz

#14 downplay

downplay

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 11 March 2006 - 04:11 PM

thnx for posting this :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users