Latest news from Xavier Media
It is currently Mon Feb 06, 2012 3:38 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to start writing your own scripts
PostPosted: Sun Dec 16, 2007 3:56 pm 
Offline
XavierForum.com Admin
XavierForum.com Admin
Super VIP Member
Super VIP Member
User avatar

Joined: Tue Mar 15, 2005 4:37 pm
Posts: 1021
Location: Sweden
Points: 930
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!

_________________
Xavier Media®
PHP Password Protection | Get your latest blog post in your signature you too
Latest Blog Post: New feature for XavierForum.com members


Report this post
Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Registered users: No registered users


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Portal » Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[
SEO MOD © 2007 StarTrekGuide ]