.php

Discussion in 'The Living Room' started by Alexis, Sep 8, 2003.

  1. #1
    Alexis

    Alexis Extremely H! Vltg3

    Joined:
    Jul 21, 2003
    Messages:
    899
    Likes Received:
    0



    Hey --

    I'm pretty ok with html but I haven't used .php file extensions yet. Could anybody tell me
    a ) when to use them
    b ) how to use them
    c ) any msc information regarding them
    d ) or reccomend a really good tutorial for them?

    Any help would be greatly appreciated :)

    -- Alexis
     
  2. #2
    Kæton

    Kæton is Keaton LPA Über VIP

    Joined:
    Oct 16, 2002
    Messages:
    10,388
    Likes Received:
    1



    I'm going to warn you now that PHP can be seriously confusing.

    You usually use PHP for things like forums--stuff to tell you current things or more on the line of interaction, cookies, status, etc.

    The tutorials you find out there are not good enough for you to understand a lot... I tried to learn PHP awhile back, but I got really pissed because I only understood how to do includes, and that's about it.

    PHP is long, usually, but it makes pages using the same stuff easier to use (in some cases), but it takes a lot of work and such to like... understand it.

    Bottom line--If you want to learn PHP, it'll take longer than HTML, that's for sure. Hopefully you have more luck than I did learning the thing :lol:.
     
  3. #3
    Alexis

    Alexis Extremely H! Vltg3

    Joined:
    Jul 21, 2003
    Messages:
    899
    Likes Received:
    0



    So what do you use as an alternative (my friend told me they're used for layouts with tables) to .php?

    Thanks for your advice, though :lol:
     
  4. #4
    Alex

    Alex Ambient

    Joined:
    Jul 13, 2002
    Messages:
    1,552
    Likes Received:
    0



    PHP is a free server-side programming language which you can "code" your WebPages with and plug your site into a database ect ect. You could think about it like HTML on hard drugs. LPA has all of its content stored in one database, none of the "content" you see is hard-coded as html, this is good because we can use our 'content management system' (CMS) to update the site at anytime just by updating the data in the database, no uploading new pages needed

    Of course PHP is not the only server-side programming language. You can also find the likes of; Perl & Python (.cgi), JavaServer Pages (.jsp), Active Server Pages (.asp), Cold Fusion (.cfm)

    PHP can be as simple as importing a another file or as complex as this forum depending on what you want to do.

    Below is just a little snippet of the code from this invision forum ;)


    Code:
    <?php
    
    /*
    +--------------------------------------------------------------------------
    |   Invision Power Board v1.1
    |   ========================================
    |   by Matthew Mecham
    |   (c) 2001,2002 Invision Power Services, Inc
    |   http://www.ibforums.com
    |   ========================================
    |   Web: http://www.ibforums.com
    |   Email: [email][email protected][/email]
    |   Licence Info: [email][email protected][/email]
    +---------------------------------------------------------------------------
    |
    |   > Wrapper script
    |   > Script written by Matt Mecham
    |   > Date started: 14th February 2002
    |
    +--------------------------------------------------------------------------
    */
    
    
    //-----------------------------------------------
    // USER CONFIGURABLE ELEMENTS
    //-----------------------------------------------
     
    // Root path
    
    $root_path = "./";
    
    //-----------------------------------------------
    // NO USER EDITABLE SECTIONS BELOW
    //-----------------------------------------------
     
    error_reporting  (E_ERROR | E_WARNING | E_PARSE);
    set_magic_quotes_runtime(0);
    
    class Debug {
        function startTimer() {
            global $starttime;
            $mtime = microtime ();
            $mtime = explode (' ', $mtime);
            $mtime = $mtime[1] + $mtime[0];
            $starttime = $mtime;
        }
        function endTimer() {
            global $starttime;
            $mtime = microtime ();
            $mtime = explode (' ', $mtime);
            $mtime = $mtime[1] + $mtime[0];
            $endtime = $mtime;
            $totaltime = round (($endtime - $starttime), 5);
            return $totaltime;
        }
    }
    
    class info {
    
    	var $member     = array();
    	var $input      = array();
    	var $session_id = "";
    	var $base_url   = "";
    	var $vars       = "";
    	var $skin_id    = "0";     // Skin Dir name
    	var $skin_rid   = "";      // Real skin id (numerical only)
    	var $lang_id    = "en";
    	var $skin       = "";
    	var $lang       = "";
    	var $server_load = 0;
    	var $version    = "v1.1.2";
    	var $lastclick  = "";
    	var $location   = "";
    	var $debug_html = "";
    
    	function info() {
      global $sess, $std, $DB, $root_path, $INFO;
      
      $this->vars = &$INFO;
      
      $this->vars['TEAM_ICON_URL']   = $INFO['html_url'] . '/team_icons';
      $this->vars['AVATARS_URL']     = $INFO['html_url'] . '/avatars';
      $this->vars['EMOTICONS_URL']   = $INFO['html_url'] . '/emoticons';
      $this->vars['mime_img']        = $INFO['html_url'] . '/mime_types';
    
    	}
    }
    
    //--------------------------------
    // Import $INFO, now!
    //--------------------------------
    
    require $root_path."conf_global.php";
    
    //--------------------------------
    // The clocks a' tickin'
    //--------------------------------
      
    $Debug = new Debug;
    $Debug->startTimer();
    
    //--------------------------------
    // Require our global functions
    //--------------------------------
    
    require $root_path."sources/functions.php";
    
    $std   = new FUNC;
    $print = new display();
    $sess  = new session();
    
    //--------------------------------
    // Load the DB driver and such
    //--------------------------------
    
    $INFO['sql_driver'] = !$INFO['sql_driver'] ? 'mySQL' : $INFO['sql_driver'];
    
    $to_require = $root_path."sources/Drivers/".$INFO['sql_driver'].".php";
    require ($to_require);
    
    $DB = new db_driver;
    
    $DB->obj['sql_database']     = $INFO['sql_database'];
    $DB->obj['sql_user']         = $INFO['sql_user'];
    $DB->obj['sql_pass']         = $INFO['sql_pass'];
    $DB->obj['sql_host']         = $INFO['sql_host'];
    $DB->obj['sql_tbl_prefix']   = $INFO['sql_tbl_prefix'];
    
    $DB->obj['debug']            = ($INFO['sql_debug'] == 1) ? $_GET['debug'] : 0;
    
    // Get a DB connection
    
    $DB->connect();
    
    //--------------------------------
    // Wrap it all up in a nice easy to
    // transport super class
    //--------------------------------
    
    $ibforums             = new info();
    
    //--------------------------------
    //  Set up our vars
    //--------------------------------
    
    $ibforums->input      = $std->parse_incoming();
    $ibforums->member     = $sess->authorise();
    $ibforums->skin       = $std->load_skin();
    $ibforums->lastclick  = $sess->last_click;
    $ibforums->location   = $sess->location;
    $ibforums->session_id = $sess->session_id;
    
    list($ppu,$tpu) = explode( "&", $ibforums->member['view_prefs'] );
      
    $ibforums->vars['display_max_topics'] = ($tpu > 0) ? $tpu : $ibforums->vars['display_max_topics'];
    $ibforums->vars['display_max_posts']  = ($ppu > 0) ? $ppu : $ibforums->vars['display_max_posts'];
    
    if ($ibforums->member['id'] and ( $std->my_getcookie('hide_sess') ) )
    {
    	$ibforums->session_id = "";
    }
    
    $ibforums->base_url   = $ibforums->vars['board_url'].'/index.'.$ibforums->vars['php_ext'].'?s='.$ibforums->session_id;
    
    $ibforums->skin_rid   = $ibforums->skin['set_id'];
    $ibforums->skin_id    = 's'.$ibforums->skin['set_id'];
    
    $ibforums->vars['img_url']   = 'style_images/' . $ibforums->skin['img_dir'];
    
    //--------------------------------
    //  Set up our language choice
    //--------------------------------
    
    if ($ibforums->vars['default_language'] == "")
    {
    	$ibforums->vars['default_language'] = 'en';
    }
    
    $ibforums->lang_id = $ibforums->member['language'] ? $ibforums->member['language'] : $ibforums->vars['default_language'];
    
    if ( ($ibforums->lang_id != $ibforums->vars['default_language']) and (! is_dir( $root_path."lang/".$ibforums->lang_id ) ) )
    {
    	$ibforums->lang_id = $ibforums->vars['default_language'];
    }
      
    $ibforums->lang = $std->load_words($ibforums->lang, 'lang_global', $ibforums->lang_id);
    
    //--------------------------------
    
    $skin_universal = $std->load_template('skin_global');
    
    //--------------------------------
    
    if ($ibforums->input['act'] != 'Login' and $ibforums->input['act'] != 'Reg' and $ibforums->input['act'] != 'Attach')
    {
    
    	//--------------------------------
    	//  Do we have permission to view
    	//  the board?
    	//--------------------------------
    	
    	if ($ibforums->member['g_view_board'] != 1)
    	{
      $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_view_board') );
    	}
    	
    	//--------------------------------
    	//  Is the board offline?
    	//--------------------------------
    	
    	if ($ibforums->vars['board_offline'] == 1)
    	{
      if ($ibforums->member['g_access_offline'] != 1)
      {
      	$std->board_offline();
      }
      
    	}
    	
    	//--------------------------------
    	//  Is log in enforced?
    	//--------------------------------
    	
    	if ( (! $ibforums->member['id']) and ($ibforums->vars['force_login'] == 1) )
    	{
      require $root_path."sources/Login.php";
      
    	}
    
    }
    
    //--------------------------------
    // Decide what to do
    //--------------------------------
    
    $choice = array(
                     "idx"      => "Boards",
                     "SF"       => "Forums",
                     "SR"       => "Forums",
                     "ST"       => "Topics",
                     "Login"    => "Login",
                     "Post"     => "Post",
                     "Poll"     => "lib/add_poll",
                     "Reg"      => "Register",
                     "Online"   => "Online",
                     "Members"  => "Memberlist",
                     "Help"     => "Help",
                     "Search"   => "Search",
                     "Mod"      => "Moderate",
                     "Print"    => "misc/print_page",
                     "Forward"  => "misc/forward_page",
                     "Mail"     => "misc/contact_member",
                     "Invite"   => "misc/contact_member",
                     "ICQ"      => "misc/contact_member",
                     "AOL"      => "misc/contact_member",
                     "YAHOO"    => "misc/contact_member",
                     "MSN"      => "misc/contact_member",
                     "report"   => "misc/contact_member",
                     "chat"     => "misc/contact_member",
                     "Msg"      => "Messenger",
                     "UserCP"   => "Usercp",
                     "Profile"  => "Profile",
                     "Track"    => "misc/tracker",
                     "Stats"    => "misc/stats",
                     "Attach"   => "misc/attach",
                     'ib3'      => 'misc/ib3',
                     'legends'  => 'misc/legends',
                     'modcp'    => 'mod_cp',
                     'calendar' => "calendar",
                     'buddy'    => "browsebuddy",
                   );
    
                    
    /***************************************************/
    
    $ibforums->input['act'] = $ibforums->input['act'] == '' ? "idx" : $ibforums->input['act'];
    
    // Check to make sure the array key exits..
    
    if (! isset($choice[ $ibforums->input['act'] ]) )
    {
    	$ibforums->input['act'] = 'idx';
    }
    
    // Require and run
    
    require $root_path."sources/".$choice[ $ibforums->input['act'] ].".php";
    
    
    
    //+-------------------------------------------------
    // GLOBAL ROUTINES
    //+-------------------------------------------------
    
    function fatal_error($message="", $help="") {
    	echo("$message<br><br>$help");
    	exit;
    }
    ?>
    
    ^^^ I know what it all means anyway :p
     
  5. #5
    Alexis

    Alexis Extremely H! Vltg3

    Joined:
    Jul 21, 2003
    Messages:
    899
    Likes Received:
    0



    Oooh, I see. So if your page involves tables or something like that, you can just change one document and it changes everything else. Sort of like an external CSS, right? Ok. Thanks, that clears up a lot for me.
     
  6. #6
    elemynt

    elemynt Well-Known Member

    Joined:
    Jul 20, 2002
    Messages:
    199
    Likes Received:
    0



    Ok, sorry if I'm posting in an old topic but there are many advantages to PHP -

    1) $shoo = Go Away you little piece of nothing.
    *If you type this then you don't have to type "Go Away you little piece of nothing." whenever you want it, you'll just have to type $shoo instead of "Go Away you little piece of nothing." which saves a lot of time.

    2) If you want the same design but different content on each page then you can use PHP.

    It's a lazy b*stard's language, so call me one!!! :p ;)
     
  7. #7
    d0dGy MiKE

    d0dGy MiKE Well-Known Member

    Joined:
    Aug 1, 2002
    Messages:
    231
    Likes Received:
    0



    On the contrary i learnt PHP a lot more quicker than i did HTML! i was doing HTML for 2 years even before i started php - which i have done for 9 months now. and have written my own forums script. :D
     
  8. #8
    Hoodie

    Hoodie Well-Known Member

    Joined:
    Jan 12, 2003
    Messages:
    48
    Likes Received:
    0



    Erm, I find that statement not very well thought out. PHP is not a lazy bastards language. Almost all scripting languages have variables. Perl, Javascript, C++, all of it. And you wouldn't use variables only for substituting a sentence you dont want to type out. Once you start scripting large programs variables do many things... Notice in alex's code:

    Code:
    $DB->obj['sql_database']   = $INFO['sql_database'];
    $DB->obj['sql_user']     = $INFO['sql_user'];
    $DB->obj['sql_pass']     = $INFO['sql_pass'];
    $DB->obj['sql_host']     = $INFO['sql_host'];
    $DB->obj['sql_tbl_prefix']  = $INFO['sql_tbl_prefix'];
    
    $INFO is a variable that stores an array holding database info. Without that array the database driver of IPB would not run and we'd be #### out of luck in terms of this forum. Untill you fully understand PHP, I advise you not to judge it or make ignorant statements.

    BTW, your variable syntax was wrong, use this: :p
    Code:
    $shoo = "Go away you little piece of nothing.";
    
     
  9. #9
    sbauer

    sbauer Member

    Joined:
    Nov 12, 2003
    Messages:
    5
    Likes Received:
    0



    Erm, I find that statement not very well thought out. PHP is not a lazy bastards language. Almost all scripting languages have variables. Perl, Javascript, C++, all of it. And you wouldn't use variables only for substituting a sentence you dont want to type out. [/b][/quote]
    Actually, PHP is a very lazy ass language.

    Most programming languages are strongly typed (ie require you to pass it a specific data type when you send it data)

    For example, in PHP, you could do this.

    Code:
    $page = 1;
    $page = "hello";
    
    PHP doesn't complain, but if you did that in C# like:

    Code:
    int page = 1;
    page = "hi";
    
    C# would complain. Like other scripting languages, PHP tries to make it easy.

    Secondly, you don't have to specifically declare variables in PHP. For example, you would have to declare a variable in C# before you could use it.

    Code:
    int page;
    
    PHP's way may sound better. But when you're writing a 5000 line script and you figured out that your program isn't working correctly because you accidently typed $pge instead of $page, it makes it a pain in the ass.

    IMO, I believe PHP CAN teach programmers bad habits because of these examples. It makes it more difficult to transit from PHP to a more difficult language.
     
  10. #10
    Hoodie

    Hoodie Well-Known Member

    Joined:
    Jan 12, 2003
    Messages:
    48
    Likes Received:
    0



    Well, yes C's vars are more complex, but still. Calling PHP a lazy illegitimate offspring of unmarried parents's language because of variables was not right. It would have been slighty more appropriate if they mentioned your point, sbauer, but still not very. Thats basically flaming anyone who uses it. You could easily tell they didnt know what they were talking about. :whistle:
     
  11. #11
    Bryan

    Bryan Guest




    Does it really matter? As long as what you want gets done it's all good.
     
  12. #12
    sbauer

    sbauer Member

    Joined:
    Nov 12, 2003
    Messages:
    5
    Likes Received:
    0



    Hoodie: I understand and I hope you weren't taking my comments as flames. I respect the PHP developers and the language.

    Bryan: Yes and no. If you're working on your site and you get what you want, then no it doesn't. If you tell someone to learn PHP because it's so hard and it will teach you how to program in any language, then yes it does. I honestly don't think that PHP should be the first language that someone learns.
     
  13. #13
    Phantom Duck

    Phantom Duck You are my detonator. LPA Super Member

    Joined:
    Mar 14, 2003
    Messages:
    3,727
    Likes Received:
    0



    I'd bet that.
     
  14. #14
    sbauer

    sbauer Member

    Joined:
    Nov 12, 2003
    Messages:
    5
    Likes Received:
    0



    I'd bet that. [/b][/quote]
    You would bet what?
     

Share This Page