This is actually a really old article I wrote a couple of years ago, but it deserves to be posted here anyway as an easy start for beginners
.
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 for test.php: |
| <? 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 for test.php: |
| <? if ($_REQUEST[print] == “hello”) echo “Hello world!”; else if ($_REQUEST[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 for cookie.php: |
| <? // Checking if the visitor has a cookie in his brower, otherwise the script will set one. if (!isset($_COOKIE[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”,$_COOKIE[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!
#1 fotinorod - 07 July, 4:57 PM
Hi
I am Lucy, I have found your website while searching for some info at Google. Your site has helped me in a big way.
G’night