Php Newbie

Discussion in 'PHP' started by AlexaCY, Jun 13, 2007.

  1. #1
    i just wanted to ask how much does it take to learn php.:D

    and what do we have to learn with php to be a better webmaster
     
    AlexaCY, Jun 13, 2007 IP
  2. gfreeman

    gfreeman Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are some great web resources out there, and some good books too. Was it a bunch of links you wanted, book recommendations, or just an idea on how easy it is?

    Because it's very eaesy to learn the basics. First, find a hoster that offers php (they all do, pretty much) if you can't or don't want to install it on your own computer. If you use a hosting company, you upload the files to test them.

    Start with the usual helloworld.php :

    <?php
    echo "Hello World!";
    ?>
    PHP:
    then grow from that. I assume you are familiar with HTML? PHP is, I guess, the next step up.
     
    gfreeman, Jun 13, 2007 IP
  3. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Theres been roughly a GAJILLION posts regarding this.. try using the search feature ;)
     
    CodyRo, Jun 13, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    gajillion+1

    I'd also like to say that tutorials and snippets such as

    
    <?php
    echo "Hello World!";
    ?>
    
    PHP:
    and

    
    <?php
    include('somefile.php');
    ?>
    
    PHP:
    are a total waste of using php in the first place, why not just write

    Hello World

    on an html page and upload it to your server and as for the includes() abuse, php is much more than some glue with which to stick your badly made pages together in an attempt to save you ten minutes
     
    krakjoe, Jun 13, 2007 IP
  5. gfreeman

    gfreeman Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    In my defence ... :)

    The next step after understanding what "echo" does, is to replace "Hello World" with $foo and $bar. Then muck around with setting those variables so the newbie understands that the output to the page can be altered by changing $foo and $bar. Writing static HTML doesn't help learning PHP.
     
    gfreeman, Jun 13, 2007 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    I live under the assumption that my thoughts and intentions don't actually mean anything, it's my actions that count, and while your defense is a good one, it's void, you didn't do any of that.

    A 10 minute explanation of how variables and formatting those variables with sprintf ( and complementing functions ) would have been worlds better than what you did, however it still wouldn't really be helpful to someone who doesn't understand what php is or does or what its supposed to ( or can be ) used for, it would be about as much help as static html, oh wait, that's what he got .....writing static html is exactly what you did, it's never going to change and so might aswell be static html ......
     
    krakjoe, Jun 13, 2007 IP
  7. gfreeman

    gfreeman Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This is where we differ. I'll take someone step by step, making sure they understand it all along the way. You give them all the answers in one hit.

    You have much more patience than I do, which is why you're exceedingly good at this. I remember being confused to death by someone explaining classes and so on, when I first encountered it all - I had to be taken on a journey learning each step.

    I envy you ;)
     
    gfreeman, Jun 13, 2007 IP
  8. xxxcoder

    xxxcoder Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    gd library-random number & png image create
    
    <?
    
    $imagekod = '';
    
    for ($i = 0; $i < 8; $i++) {
    
    $imagekod .= chr(mt_rand(100,120));
    $imagekod=strtoupper($imagekod);
    }
    // set up image
    $height = 30;
    $width = 100;
    $im = ImageCreate($width, $height);
    $white = ImageColorAllocate ($im, 255, 255, 255);
    $black = ImageColorAllocate ($im, 128, 0, 0);
    
    // draw on image
    ImageFill($im, 0, 0, $black);
    // ImageLine($im, 0, 0, $width, $height, $white);
    ImageString($im, 300, 15, 10, $imagekod, $white);
    
    // output image
    Header ("Content-type: image/png");
    ImagePng ($im);
    
    // clean up
    ImageDestroy($im);
    
    ?> 
    
    PHP:
     
    xxxcoder, Jun 13, 2007 IP
  9. xxxcoder

    xxxcoder Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    phpinfo samples
    <?php
    echo "<font color=red> IP ::</font> $REMOTE_ADDR<br>";
    $gun=date("D");
    $ay=date("n")-1;
    $yil=date("Y");
    $gun_sayi=date('d');
    echo "<font color=red> Date ::</font> $gun_sayi $ay $yil $gun<BR>";
    echo "<font color=red> Server Version ::</font> $SERVER_SOFTWARE<br>";
    echo "<font color=red> Script Language ::</font> $GATEWAY_INTERFACE<br>";
    echo "<font color=red> Command Program Location ::</font> $COMSPEC<br>";
    echo "<font color=red> Browser Version ::</font> $HTTP_USER_AGENT<br>";
    echo "<font color=red> Windows Folder ::</font> $WINDIR<br>";
    echo "<font color=red> Connect Type ::</font> $HTTP_CONNECTION<br>";
    echo "<font color=red> Server Name ::</font> $SERVER_NAME<br>";
    echo "<font color=red> Accept Coding ::</font> $HTTP_ACCEPT_ENCODING<br>";
    echo "<font color=red> File Location and Name ::</font> $PATH_INFO<br>";
    echo "<font color=red> Server Port ::</font> $SERVER_PORT<br>";
    echo "<font color=red> Referer Page ::</font> $HTTP_REFERER<br>";
    ?> 
    PHP:
     
    xxxcoder, Jun 13, 2007 IP
  10. xxxcoder

    xxxcoder Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    php form control
    
    /////////////////////////////////////////////////////////////// 
    FORM PAGE
    ///////////////////////////////////////////////////////////////
    
    <form name="form1" method="post" action="check.php">
    <table width="50%" border="0" align="center" cellpNameding="0" cellspacing="2">
    <tr> 
    <td width="43%"><div align="center">Name :</div></td>
    <td width="57%"><div align="center"> 
    <input name="txt_Name" type="text" id="txt_Name">
    </div></td>
    </tr>
    <tr> 
    <td><div align="center">SurName :</div></td>
    <td><div align="center"> 
    <input name="txt_SurName" type="text" id="txt_SurName">
    </div></td>
    </tr>
    <tr> 
    <td colspan="2"><div align="center"> 
    <input type="submit" name="Submit" value="Submit">
    </div></td>
    </tr>
    </table>
    </form>
    
    ///////////////////////////////////////////////////////////////
    check.php Page
    ///////////////////////////////////////////////////////////////
    <?php
    if(empty($_POST[txt_Name])){
    echo("<center><b>Name Field Empty. Go Back Fillng Please.</b></center>");
    }elseif(empty($_POST[txt_SurName])){
    echo("<center><b>SurName Field Empty. Go Back Fillng Please.</b></center>");
    }else{
    echo("All Field Full.");
    }
    ?> 
    
    PHP:
     
    xxxcoder, Jun 13, 2007 IP
  11. xxxcoder

    xxxcoder Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    evident space create random number
    
    $lower = 1; // start number
    $upper = 50; // finish number
    $random_number = mt_rand($lower, $upper); // select random number 
    echo $random_number;
    
    PHP:
     
    xxxcoder, Jun 13, 2007 IP
  12. xxxcoder

    xxxcoder Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    this is computer uptime
    
    <?php
    
    $uptime_array = explode(" ", exec("cat /proc/uptime"));
    $seconds = round($uptime_array[0], 0);
    $minutes = $seconds / 60;
    $hours = $minutes / 60;
    $days = floor($hours / 24);
    $hours = floor($hours - ($days * 24));
    $minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60));
    $seconds = floor($seconds - ($days * 24 * 60 * 60) - ($hours * 60 * 60) -
    ($minutes * 60));
    $uptime_array = array($days, $hours, $minutes, $seconds);
    
    if ($uptime_array[0] == 0) {
    if ($uptime_array[1] == 0) {
    if ($uptime_array[2] == 0) {
    print("This computer is on time: <b>" . $uptime_array[3] . " second</b>");
    }
    
    else {
    print("This computer is on time: <b>" . $uptime_array[2] . " minute</b>");
    }
    }
    
    else {
    print("This computer is on time: <b>" . $uptime_array[1] . " hour</b>");
    }
    }
    
    else {
    print("This computer is on time: <b>" . $uptime_array[0] . " day</b>");
    }
    ?> 
    
    PHP:
     
    xxxcoder, Jun 13, 2007 IP
  13. xxxcoder

    xxxcoder Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    random banner show
    this is sql query for banners table
    
    
    CREATE TABLE banners (
    id int(11) NOT NULL auto_increment,
    url varchar(50) default NULL,
    banner varchar(50) default NULL,
    PRIMARY KEY (id)
    ) TYPE=MyISAM;
    
    
    
    INSERT INTO banners VALUES (1,'http://fedora.redhat.com','http://destan.sdu.edu.tr/resimler/redhat.jpg');
    INSERT INTO banners VALUES (2,'http://www.debian.org','http://destan.sdu.edu.tr/resimler/debian.jpg');
    INSERT INTO banners VALUES (3,'http://destan.sdu.edu.tr','http://destan.sdu.edu.tr/resimler/ismail.gif');
    INSERT INTO banners VALUES (4,'http://www.suse.de','http://destan.sdu.edu.tr/resimler/suse.png');
    
    PHP:
    this is print screen code
    
    <HTML>
    <HEAD>
    <meta http-equiv="Content-Type" Content="text/html; charset=UTF-8">
    <meta http-equiv="Content-Language" Content="tr">
    <title>XXXCODER Random Banner</title>
    </HEAD>
    </HTML>
    
    <?php
    
    mysql_connect("localhost", "username", "password");
    mysql_select_db("dbname"); // database name
    $sorgu = mysql_query("select * from banners order by rand() Limit 0,2"); // Limit 0 than  2 data fetch
    if(!mysql_num_rows($sorgu))
    {
    echo "No Image";
    }
    else
    {
    while($res = mysql_fetch_array($sorgu))
    {
    $url = $res['url'];
    $banner = $res['banner'];
    echo "<a href=\"$url\"
    target=\"_self\"><img src=\"$banner\" alt=\"\" border=\"0\"></a>";
    }
    }
    ?> 
    
    PHP:
     
    xxxcoder, Jun 13, 2007 IP
  14. xxxcoder

    xxxcoder Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    mail send form
    
                                                                                                                   
    <form method="post" action="formmail.php"> 
    <input type="text" name="recipient" value="[Your Mail]"> 
    <input type="text" name="subject" value="[Subject]"> 
    <input type="hidden" name="req" value="[required field]"> 
    <input type="submit" value="send">
    [back form part add code]
    </form> 
    --------------------------------------------------------------------------
    [ formmail.php ]
    <html> 
    <head> 
    <title>Formmail</title> 
    </head> 
    <body bgcolor="black"> 
    
    <? 
    //---------------------------------- 
    // OPTIONAL PARAMETERS 
    //---------------------------------- 
    
    // Message header such as "confirm" or "error" 
    $headersize="4"; 
    $headercolor="Lime"; 
    // Message body 
    $textsize="3"; 
    $textcolor="0000ff"; 
    $linkcolor="ffcc99"; 
    
    
    /*****************************************************/ 
    /* YOU DO NOT NEED TO MODIFY ANYTHING BELOW */ 
    /***************************************************/ 
    
    
    
    
    if( !empty($HTTP_POST_VARS)) 
    { 
    // if any form submission start the process 
    function prompt_user($messageheader,$promptmessage) 
    { 
    global $l,$goback,$fm_error,$plsfill,$invalidaddress,$fm_confirm,$sent,$unsent,$author; 
    global $headersize,$headercolor,$textsize,$textcolor,$linkcolor; 
    include("inc/Header.php"); 
    echo " 
    
    <center> 
    <B><font size=\"$headersize\" color=\"$headercolor\"> 
    ----------------------------<br> 
    :: ::<br> 
    ----------------------------<br> 
    </font> 
    <br> 
    <font size=\"$textsize\" color=\"$textcolor\"> 
    Message Succesfly Send!..</font> 
    <br><br> 
    <a href='javascript:history.go(-2)'> 
    <font size='2' color='$linkcolor'>Back Main</font></a> 
    <B></center>"; 
    exit; 
    } 
    
    // function to check the empty fields 
    function check_fields($fieldname,$fieldtype) 
    { 
    global $fm_error,$plsfill; 
    if (empty($fieldname)) 
    { 
    prompt_user("$fm_error","$plsfill <br> * $fieldtype"); 
    } 
    } 
    
    // function to check the email validity 
    function check_email($mailtocheck) 
    { 
    global $fm_error,$plsfill,$invalidaddress; 
    $mail_test= trim($mailtocheck); 
    if (!eregi("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,3}$", $mail_test)) 
    { 
    prompt_user("$fm_error","$invalidaddress :<br> $mail_test"); 
    } 
    } 
    
    // check if there are required fields 
    if ($req) 
    { 
    $requiredfields=explode(",",$req); 
    for ($temp=0;$temp<count($requiredfields);$temp++) 
    { 
    $requiredfields[$temp]=trim ($requiredfields[$temp]); 
    if ($requiredfields[$temp]=="email") 
    { 
    check_email("${$requiredfields[$temp]}"); 
    } 
    else 
    { 
    check_fields ("${$requiredfields[$temp]}","$requiredfields[$temp]"); 
    } 
    } 
    } 
    
    /* default values for script will take place in the text form fields */ 
    $def[]="subject"; 
    $def[]="req"; 
    $def[]="recipient"; 
    
    // get the IP and the date 
    $ip=getenv("REMOTE_ADDR"); 
    $date=date("d-m-Y H:i:s"); 
    
    // message body 
    $message=$defaultmessage."\n\n"; 
    $message.="From :".$email."\n"; 
    $message.="Date :".$date."\n"; 
    $message.="IP :".$ip."\n"; 
    $message.="------------------------------------\n"; 
    foreach($HTTP_POST_VARS as $formfield => $value) 
    { 
    $found=0; 
    for($i=0;$i<count($def);$i++) 
    { 
    if($formfield==$def[$i]) 
    { 
    $found=1; 
    } 
    } 
    if(!$found==1) 
    { 
    $message.=$formfield." : ".$value."\n"; 
    } 
    } 
    $message.="------------------------------------\n\n\n"; 
    $message.=""; 
    $headers ="From: $email\n"; 
    
    // check the subject 
    if(!$subject) 
    { 
    $subject=$defaultsubject; 
    } 
    
    // mail the form 
    if(@mail($recipient,$subject,$message,$headers)) 
    { 
    prompt_user("$fm_confirm","$sent"); 
    echo"<center></center>"; 
    } 
    else 
    { 
    prompt_user("$fm_error","$unsent"); 
    echo"<center></center>"; 
    } 
    } 
    else 
    { 
    echo"<center><font face=System color=lime> <br> 
     Message gonderilmedi!..<br>Fatal ERROR: 000FFFFx000DEEE</font></center>"; 
    } 
    
    ?> 
    </body> 
    </html>  
    
    PHP:
    to be contunied...
     
    xxxcoder, Jun 13, 2007 IP
  15. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #15
    omg what the hell are you doing, none of that is usefull to him you're just spamming the forum with useless code, stop it .....
     
    krakjoe, Jun 13, 2007 IP
  16. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #16
    These codes of xxxcoder is not helpful at all for a newbie.he is just wasting the spaces.
    AlexaCY better downloads some PHP tutorials and read them.it will be more if you get a book on PHP.worx's books are better.
     
    coderbari, Jun 13, 2007 IP
  17. ProgrammersTalk

    ProgrammersTalk Peon

    Messages:
    684
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #17
    lol.. I think this post is the most funny over all the rest.. lol..
     
    ProgrammersTalk, Jun 13, 2007 IP
  18. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #18
    Probably trying to build up posts. Pretty useless code and irrelevant to the thread.
     
    einsteinsboi, Jun 13, 2007 IP
  19. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #19

    Well, I don't know what my advice is worth since I am also starting to learn PHP but this is my approach. I have some projects in mind but I don't know PHP. So I picked up a book "Beginning PHP5, Apache, And MySQL Web Development (2005)". I chose it because it teaches you PHP and mySQL through the process of creating applications, so you get to see a finished product as you learn. That's how I've learned programming languages before, by actually coding a project. Anyway, I then spent some time installing Apache, PHP and mySQL individually on my laptop so that I can develop on my laptop without having to upload every single program I write to my host to test it. Finally, I read through the forums to figure out the best editor to use and downloaded it. I settled on Notepad++ and PHP Designer because I have commitment issues :D and like to have options, but I'll probably end up deciding on one and sticking with it.

    Now I have started working through the book, typing on all the snippets of code and testing them. Also I will be posting here and asking questions and reading what others post.

    Good luck with learning!!
     
    einsteinsboi, Jun 13, 2007 IP
  20. tfusion

    tfusion Peon

    Messages:
    566
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #20
    I have some tutorials about PHP basics at www.tutbox.com Check it out if u wan ;)
     
    tfusion, Jun 13, 2007 IP