When you write a PHP script you should put your PHP code between <? ?> tags. Each line of code should also be ended with ; like this:
Code:
<?
echo "<B>Hello world!</B>";
?>
This will print
Hello world! on your page. You can also make the script a little bit more dynamic and just not print Hello world!. This can be done with variables and if statements:
Code:
<?
if ($print == "hello")
echo "Hello world!";
else if ($print == "xavier")
echo "Xavier Media Group";
else
echo "Nothing";
?>
Now you can access
test.php as
test.php?print=hello. That will print
Hello world! on your screen. If you instead visit
test.php?print=xavier that will print
Xavier Media Group.
If you use cookies you can do some really cool stuff. The code below will count the number of times a user has visited your page:
Code:
<?
// Checking if the visitor has a cookie in his brower, otherwise the script will set one.
if (!isset($countercookie))
{
// Set the cookie for one year
Setcookie("countercookie",1,time()+31536000);
// Print a message
echo "This is your first visit to this page!";
}
else
{
// Increase the cookie value by one
Setcookie("countercookie",$countercookie+1,time()+31536000);
// Print a message
echo "Welcome back! You have visited this page $countercookie times before.";
}
?>
With a little imagination you can create fantastic scripts. Good luck!