Forum Moderators: open
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)