Forum Moderators: open

Message Too Old, No Replies

Anyway to check a URL for details?

Or am I trying with the wrong language

         

spica42

4:42 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



I'm writing a script for fun. It takes in a web address and calculate a certain value. However, I want to check if the URL exists. How do I do that?

The script should return a certain value if the URL does not exist.

Or must it be done with some other language?

DrDoc

4:45 pm on Jun 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should consider a server side language such as PHP/Perl/ASP. However, when you say "check if the URL exists", what exactly do you mean?

spica42

12:31 am on Jun 22, 2004 (gmt 0)

10+ Year Member



Well, I want to check if a particular URL is avaliable. That means that when I type the URL into the address bar, a page will load.

I should be able to check if this page is a 404 error page or if the domain isn't regestered at all.

DrDoc

12:32 am on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ever tried a
whois
service? ;)

spica42

1:06 am on Jun 22, 2004 (gmt 0)

10+ Year Member



I want to change this tutorial to so that the script sets a certain value to say variable 'NUM' when the URL exists.

Then I want to pass the value of NUM to another .js script.

However I can't seems to get the below mention tutorial to work? Is it correct? When I paste the php codings, my browser shows part of the php coding!
----------------------------------------------------

This tutorial is an example of what you could possibly make with my other tutorial on using forms with PHP variables. I added in some lines of code, removed others, and came up with a simple way to check if a link is valid or not. Perfect if you want a fast way to check if a link is broken on your site or not.

The first bit of the code is a form. When you enter the URL into the form, it will copy over the variable of the text field and place it where it is needed.

In short, this tutorial will make a form. When you type in a URL, the page will tell you if the page is online or not.

Click next to go on to the form code!

here is the code for the form that will appear on the site.

<form action="valid.php" method="post">
<table width="75%" border=0>
<tr>
<td>Site Address (don't include http)</td>
<td><input type="text" name="var"></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="Submit"></td>
<td><input name="reset" type="reset" value="Reset"></td>
</tr>
</table>
</form>

As you can see, the action of the form is set to valid.php. This will be the name that you save this entire project as. (worry about that later)

Also notice that the name property of the first input is 'var'. This is the variable that will be used in the PHP code.. you shouldn't have to change this unless you have another variable on you page somewhere with that name.

Very simple... copy and paste where you want the form Next, on to the PHP!

Here's where the code finally picks up!

<?php
// checks the site in the text field.. uses fsockopen function
$site = fsockopen("".$_POST['var']."", 80, &$errno, &$errstr, 30);

// if the site doesn't exist... display offline message
if(!$site) {
echo ("<b>".$_POST['var']."<font color=\"red\"> is offline</font></b>\n");
// if the site does exist... display online message..duh
} else {
echo("<a href=\"http://".$_POST['var']."\">".$_POST['var']."</a> is online"); }
?>

$_POST['var'] in the code above is the variable for the text inside the form. The name of the text field was "var" and here is where we put it to good use.

Once again, it's pretty much copy and paste... paste this where you want to display the offline or online message (I put mine right below the form)

spica42

3:40 pm on Jun 22, 2004 (gmt 0)

10+ Year Member



Oh well, I think I've got it figured out.

Just wondering if there's an equlivent of the PHP $site function for javascript.

DrDoc

4:23 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, there is nothing like that in JavaScript.