Page 1 of 4 1234 LastLast
Results 1 to 25 of 93

Thread: Basics Of PHP

  1. #1

    Basics Of PHP

    I figured it's time to make a small tutorial , by reading this tutorial you should have the basic know how to execute small script's on your php enabled servers. Note that i will not be explaining how to set up a web server + php.

    What Does PHP Stand For?

    PHP- Hypertext Preprocessor

    Starting & Ending Tags


    We start off by learning the 2 main tag's that you must never forget , that is the starting and ending tag's.

    Starting
    Code:
    <?php
    Ending
    Code:
    ?>
    Baisc Syntax

    Now that you know about the starting & ending tag's , let's start with a basic script.
    Code:
    <?php
    echo "This is my first php script!";
    ?>
    so you have noticed echo , echo is simple, it output's the text "This is my first php script!" , now you must end this with a semicolon , why? the semicolon is a seperator and is used to distinguish one set of instructions from another.

    Variables

    Now that you know some basic syntax let's start working on variables , variables are ton's of fun and one of the most important part's of PHP.
    Code:
    <?php
    $myfirstscript = "This is my first php script!";
    echo $myfirstscript;
    ?>
    So you have noticed $myfirstscript , i made the variable $myfirstscript that hold's the string "This is my first php script!" . Then ofcourse just echo'd the variable which would output "This is my first php script!".

    Comments

    Comments are also another important thing not only in php but all languages , there used to disable any type of information inside them from actually executing with your script which ofcourse would likely cause error's.
    Code:
    //This is a comment
    /*This is
    a
    comment block*/
    Condition Statements

    Now these are fun to play with , they are used to execute certain code on a condition.
    Code:
    <?php
    $mybrowser = "Fire Fox";
    if ($mybrowser == "Fire Fox") { echo " You are using firefox!"; }
    else { echo " You are not using firefox"; }
    ?>
    So here i have set a variable equal to my browser then made a condition, if my browser is equal to firefox, output "You are using firefox" else (if your using something else) output "You are not using firefox" . Ofcourse this will not work untill i i add more to it but it give's you all a idea how condition statements work.

    Looping


    Looping is used for many many thing's , there are more then just one loop statement, ill explain how to do the "While Loop".
    Code:
    <?php
    $z = 1;
    while ($z <= 5) {
    echo $z;
    $z++
    }
    Again i made a variable named z with the value of 1 , then stated while z is less or equal to 5
    Code:
    while ($z <= 5)
    output the value of z
    Code:
    echo $z
    , increase z by 1
    Code:
    $z++
    . Which would output 1-5 on your page. Simple isn't it?

    Forms


    Now im assuming you have some basic understanding of html, although i will give an example of the html form but i will not be explaining it.
    Code:
    <form action="form.php" method="post">
    Name: <input type="text" name="name">
    <input type="submit" value="Submit">
    That's the html form , very simple. Now to the fun part.
    Code:
    <?php
    $name = $_POST["name"];
    echo "Hello ". $name;
    ?>
    Now here you have noticed something new and that would be "$_POST["name"]", $_POST is a variable already set by php , it recieved the information givin in the html form , notice the name="name" in the html form and ["name"] in $_POST.

    Now this is the end of this small basic tutorial , you should now have the knowledge to execute simple script's on your server's.

  2. #2
    I would suggest editing $mybrowser = "Fire Fox"; to something less browser related. There are actually people out there who might think this code determines what browser is being used!

  3. #3
    Join Date
    May 2002
    Location
    NE USA (Almost Canada)
    Posts
    993
    Just An Extra Note:

    If you would like to get the PHP information from your site:

    With a plain text editor paste this in:
    Code:
    <?php phpinfo() ?>
    Name it "something.php" (or even info or phpinfo.php) and upload and then open in your browser.

    Figured that'd be good for folks who are just starting on the basics and if it's covered anywhere here already I'm not really sure.

    KGIII
    What Hosting Should Be
    A Blog as CMS, eBay, PR, and Ads?
    My personal email: KGIII <at> KGIII <dot> INFO
    Microsoft MVP 2003/2006 Categories: Shell/User and Internet Explorer (Gł Solutions)

  4. #4
    nice one, ive already learnt this but i havent used php in a while so its nice to refresh my memory abit, great post for people who want to get into php

  5. #5
    Join Date
    Apr 2005
    Posts
    1,767
    Actually for a phpinfo() I would do this, since it volunteers a lot of information about your server, that you may not neccessarily want being public.

    PHP Code:
    <?PHP

    $ip 
    getenv("REMOTE_ADDR");
    $allowed_ip "24.211.80.102"// change to your ip

    if ($ip == $allowed_ip) {

    phpinfo();

    } else {

    header("Location: /");

    }

    ?>

  6. #6
    Join Date
    Feb 2006
    Location
    Buffalo, NY
    Posts
    1,501
    Or just create the file when needed / don't name it phpinfo.php

    (Or just add a constant to the index.php to show phpinfo if defined, etc)
    Cody R.
    Hawk Host Inc. Proudly Serving websites since 2004.
    Official Let's Encrypt Sponsor

  7. #7
    Is there a function in PHP that's similar to CFHTTP? I need to read the contents of one of our sites.

  8. #8
    Is it better to use $_request instead of $_POST or $_GET? Since it does what $_POST and $_GET do anyway. Is there a drawback to using it?

  9. #9
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,382
    If your form is ONLY using the post method, use $_POST. Likewise for $_GET. If your form should accept both methods, use $_REQUEST.
    Kevin

  10. #10
    Join Date
    Jun 2006
    Location
    California
    Posts
    8
    Good short, tutorial, good for new people wanting to learn PHP.

    Next thing functions, classes and arrays!

  11. #11
    Join Date
    Mar 2006
    Posts
    984
    Nice block from SNC. However, I'd state this line:

    PHP Code:
    $ip getenv("REMOTE_ADDR"); 
    for:

    PHP Code:
    $ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : getenv("REMOTE_ADDR"); 

  12. #12
    Join Date
    Dec 2006
    Location
    PA
    Posts
    99
    thank u so much this is nice short tutorial

  13. #13
    Nicely put togethor, well done

  14. #14
    Anyone seriously looking to learn PHP should bookmark the site below. If you have any questions they can usually be answered there.

    http://www.php.net/

    The function reference is particularly useful.

    http://www.php.net/manual/en/funcref.php

  15. #15
    Join Date
    Sep 2004
    Location
    Chennai , India
    Posts
    4,632
    Quote Originally Posted by vkess
    Anyone seriously looking to learn PHP should bookmark the site below. If you have any questions they can usually be answered there.

    http://www.php.net/

    The function reference is particularly useful.

    http://www.php.net/manual/en/funcref.php
    There is no better books than the PHP manual, but the only problem is most of people find it to read e books.

  16. Hi, I'm PHP beginner. Could you advice me any free PHP engine for my site?
    Thank you

  17. #17
    Join Date
    Mar 2006
    Posts
    984
    PHP engines are mostly programmed for specific concepts. What kind of PHP engine are you looking for actually ?

  18. #18
    OpenSourceCMS has a lot of free scripts, try looking there

    so does resourceindex.com

  19. #19
    Join Date
    Mar 2006
    Posts
    984
    I received an email notification regarding a new post on this topic ... not too sure how new it is . . . have I missed something ?

  20. #20
    Join Date
    Mar 2006
    Posts
    984
    Yeah, it pretty much looked like this one:

    PHP Code:
    hmmmmmmmmmmmm 
    ain't it faizanno1 ??

  21. #21
    Join Date
    Dec 2006
    Location
    New Zealand
    Posts
    16
    Thanks, I really want to learn PHP but my head just won't get around it haha.

  22. #22
    Nice Tutorial , good for teh beginers

  23. #23
    Besides knowing what it is, I really don't know where to really start for learning PHP. I have a fair outline of HTML and grasp the basics of CSS (I only know how to work with Dreamweaver). How did you guys learn PHP? Any recommended book?

  24. #24
    Well, nice tutorial for the beginners who are just starting to wet their feet with php. After going through this basic quickie, they must go on to learn further through other resources available on the net.

  25. #25
    thanks for the info

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •