CODE
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
What the <?php echo '<p>Hello World</p>'; ?> command does is it exports The information between the 's as raw text. So it would display as
CODE
<p>Hello World</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now we will use the echo() command to display what browser the viewer is using, so we can put a big fat banner telling them to switch to Mozilla Firefox
CODE
<?php echo $_SERVER['HTTP_USER_AGENT']; ?>
An output of this code would be Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) if the user is using Mozilla. What this code does is it gets the broswer information and echos it (displays it) for the viewer.
Now we could use this to our advantage and tell them which browser they are using or if they are not using Mozilla Firefox with this code...
CODE
<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
?>
<p>You are using Internet Explorer</p>
<?php
} else {
?>
<p>You are not using Internet Explorer</p>
<?php
}
?>
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
?>
<p>You are using Internet Explorer</p>
<?php
} else {
?>
<p>You are not using Internet Explorer</p>
<?php
}
?>
The output would be
<p>You are using Internet Explorer</p> or <p>You are not using Internet Explorer</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For this one, you will need two PHP files, one for the action, and one for the HTML.
CODE
<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
That's just simple HTML you would put on a site for a form. You would fill this out and it would display a sentence of "Hi ______, you are __ years old." And this is what we're going to do now. Create a action.php file and put this in it....
CODE
Hi <?php echo $_POST['name']; ?>,
You are <?php echo $_POST['age']; ?> years old.
You are <?php echo $_POST['age']; ?> years old.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
And that concludes the noob tutorial for PHP. I hope this has helped you create great websites as it has helped me get hosting credits >_>
++++++++++++++++
Tutorials Copyright
2005 shadow skazi
++++++++++++++++


