PHP tutorial **no mysql/textfiles**

Discussion in 'Archives' started by -------owned-------, Feb 26, 2007.

PHP tutorial **no mysql/textfiles**
  1. Unread #1 - Feb 26, 2007 at 12:08 PM
  2. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

    -------owned------- Guru
    Banned

    PHP tutorial **no mysql/textfiles**

    ** copied from my application **
    PHP5 tutorial (Personal home page, now known as hypertext pre-processor)


    Want to learn PHP5? Then this is the tutorial for you =)


    lets start out with FAQ =P


    Why use PHP?


    Because it can easy connect to MySQL databases, and most servers support it (ASP only supports at Windows) and is much more easier to learn then Perl.


    What can I do with php?

    Create online shops, forums, user registrations etc. However, this tutorial will NOT show you the most advanced stuff.

    part 1

    PHP syntax.


    a php-script looks like this:
    Code:
    <?php
    code here
    ?>
    
    You can configure your php-ini file, and then you can use this:
    <?
    ?>
    or asp tags:
    <%
    %>.

    Your first PHP-script:
    Code:
    <?php
    echo "Hello world!<br>";
    ?>
    
    EVERY php tag SHALL end with ;.
    Explanation:
    The command echo outputs characters.
    The caracters in the quotes (hello world!) will be the result on the page.
    If you right-click and press view-source, only HTML code will be there. That's how php work. On windows,
    php.exe returns values as HTML. That's why all webbrowsers supports php.
    <br> is for a new row.

    Part 2


    variables


    If you're familiar to other programming languages, skip this part, only note that php vars defines with $.


    What is variables?

    Variables is a kind of file, that stores values. You can later re-use the variable.
    When "echoing" a variable, skip the quotes and write var-name (var is for varialbe).
    example:
    Code:
    <?php
    $name = "Alexander Terry";
    echo $name;
    ?>
    
    This saves alot of time, if you need to re-use variable.
    How to pass variables through pages?
    Thats simple ;)
    We're going to use sessions :)
    Syntax:
    Code:
    <?php
    session_start(); //(session register first time)
    $_SESSION['name'] = "Alexander Terry";
    echo $_SESSION['name'];
    session_unset();
    session_destroy():
    ?>
    
    on next page, you can use:
    Code:
    <?php
    session_start();
    echo $_SESSION['name'];
    session_unset();
    session_destroy();
    ?>
    
    cookies

    Cookies saves in the visitors computer (usefull for auto-logging in etc)

    Note: a cookie is just a text-file.

    Syntax:
    Code:
    <?php
    setcookie(cookiename,value);
    ?>
    
    for example:
    Code:
    <?php
    setcookie("name","-------owned-------");
    ?>
    
    This is self-explanation =P


    Re-using cookie script:
    Code:
    <?php
    if(isset($_COOKIE['name'])) {
    echo $_COOKIE['name'];
    }
    ?>
    
    This 1 is simple. You simply check if cookie is set, and if it is, the script "echos" the value.


    Part 3

    Classes and date

    To echo date on website, use:
    Code:
    <?php
    echo date("ymd");
    ?>
    
    Classes

    What is classes?

    For example, if we have the class computer, the objects can be:
    keyboard, mouse, screen etc.

    How do I use classes in PHP?
    Syntax:
    Code:
    <?php
    class Person {
    var $age;
    }
    $alex = new Person;
    alex->age="25";
    echo $alex->age;
    ?>
    
    This is good if you want to create more then 5 properties.


    Post values


    Ever wondered how sites can "know" your ip adress?
    The answer is:
    post values!

    As you said above, we used $_COOKIE which I call a post value. For example,
    look at HTML forms, we need to use that data. Open notepad.
    type this:
    Code:
    <form action="postvalue.php" method="POST">
    <input type="text" name="name">
    <input type="submit" value="Submit name!">
    <input type="reset" value="reset field">
    </form>
    
    Save this as nameform.html
    Now, save this as postvalue.php:
    Code:
    <?php
    $name = $_POST['name'];
    echo $name;
    ?>
    
    Now, start your web-server and go to http://localhost/nameform.html
    When you get to the page, fill in your name and press submit. Isn't this scary, hah? The webbrowser knows your name ;O. To do this with ip, type the following:
    Code:
    <?php
    $ip = $_SERVER['remote_addr'];
    echo $ip;
    ?>
    
    This is what I call post values. The php-program saves IP in the variable ip. In postvalue.php, you can change post to get, but change
    $name = $_POST['name']; to $name = $_GET['name']. But a reminder is too always use post when you send data, because get can only handle 4kb, and for safety. If you wanted a register.php and used get, you can see password in url. Hope you liked my basic php tutorial ;)
    Hope you all will join me scripting soon ;)
     
  3. Unread #2 - Feb 27, 2007 at 6:24 PM
  4. Jultimate
    Joined:
    Jan 21, 2007
    Posts:
    190
    Referrals:
    0
    Sythe Gold:
    0

    Jultimate Active Member
    Banned

    PHP tutorial **no mysql/textfiles**

    nice job, this comes in handy when setting up vBullitins
     
  5. Unread #3 - Feb 27, 2007 at 9:20 PM
  6. coach thorpe
    Joined:
    Dec 21, 2005
    Posts:
    1,621
    Referrals:
    3
    Sythe Gold:
    0

    coach thorpe Guru
    Banned

    PHP tutorial **no mysql/textfiles**

    Good tut, but use code commands.

    I.E.

    Code:
    This is a code command
    :)
     
  7. Unread #4 - Feb 28, 2007 at 9:42 AM
  8. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

    -------owned------- Guru
    Banned

    PHP tutorial **no mysql/textfiles**

    Thank you:)
     
< The "Help & Requests" section! | New Head user ed? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site