Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Why Choose PHP?

  1. #11
    I can one up you there niggles.
    Hee, hee, there's a lot more I use it for too :-)

    Was just letting e><ius know why it's good to learn some basic PHP which can save you a lot of time and effort in the long run.

    Perl I wouldn't touch with a 10" pole *shudder*. Once upon a time I did, but since PHP I've never looked back.

    Cheers,
    Niggles

  2. #12
    Member e><ius's Avatar
    Join Date
    Mar 2007
    Location
    So.Cal.
    Posts
    61
    u know what? i could never get the include() to ever work! i followed all the instructions on the book to make it do its job. it was intended for the footers on all my pages. possibly has to do with the server cuz i didnt install PHP pack. i think it was a default install that they put up when u rent it out.

    errr... i gave up longs ago.

  3. #13
    Senior Member Aardpsymon's Avatar
    Join Date
    Feb 2007
    Location
    St Annes (aaaa!)
    Posts
    434
    yes, installing php on the server generally is very helpful. (read: vital) Also, the php include command is a bit picky with its links.

    For example, I have the main navbar called nav.html in the root of my web server. If I was to use SSI or even a hyperlink I would reference it as "/nav.html" however php forces you to use "../../../nav.html" with varying numbers of ../ depending on depth.
    If the world doesn't stop annoying me I will name my kids ";DROP DATABASE;" and get revenge.

  4. #14
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    Okay, most of my programming here at work is either PHP or Python. That said...

    First, if you learn it, learn PHP-5. Wave of the present/very-near-future, and with enough differences from PHP-4 that when I say five I mean five.

    Second, PHP is great for getting things out the door quickly, but it requires some real discipline in order to make a large project which isn't a nightmare to maintain and upgrade.

    PHP5 helps with this by adding exceptions for error handling, which (from my Java experience) are Very Good Things when it comes to reliability. There are only so many decent ways to show that an error occurred using return values. My preference with PHP5 is in fact to use it like I might with Java--make most things an object, have a utility class that then has your "myCapitalization()" function instead of polluting the global namespace, etc.

    I guess what I'm getting at is that if you're doing PHP for small one-off homepages, most of my advice here is needlessly clunky. But I often have to deal with a codebase of PHP code which has segments written more than four years ago, so I've seen the bad side of PHP in terms of maintainability. (Code using regular expressions to parse descriptive error messages to catch errors, etc.)

    I'd place PHP in the realm of small-to-medium businesses and personal home pages. If that's the kind of work you would like to do, by all means, go for it. If the book (check your local library) isn't boring in the "I know that" sense or the "I can always check the API" sense, then it's probably worthwhile.
    [HvC]Terr: L33T Technical Proficiency

  5. #15
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    Quote Originally Posted by niggles
    * headers and footers via include(); so I only need to change 1 central file to update the entire site
    Suggestion: Use Apache's "AddHandler" functionality so that all ".phpniggles" files are "handled" by your own PHP script. That script can then make sure that the header and footer are spit out appropriately instead of you having to put them at the very beginning and very end of every file, etc.

    VERY useful if anybody besides you might edit the file and accidentally drop an include(), put content outside the middle, etc.
    [HvC]Terr: L33T Technical Proficiency

  6. #16
    AO Antique pwaring's Avatar
    Join Date
    Aug 2001
    Posts
    1,409
    Quote Originally Posted by Terr
    First, if you learn it, learn PHP-5. Wave of the present/very-near-future, and with enough differences from PHP-4 that when I say five I mean five.
    I disagree - very few webhosts (at least the ones I've come across) are ready to support PHP5, most open source PHP scripts are still written in PHP4 (last time I checked, some of them wouldn't even run under PHP5 unless certain options were set in php.ini) and most sample code out there is too. If you're ever going to need to use other people's code, you'd do well to start with PHP4, as PHP5 is not really the "wave" of the present or near future.
    Paul Waring - Web site design and development.

  7. #17
    Senior Member Aardpsymon's Avatar
    Join Date
    Feb 2007
    Location
    St Annes (aaaa!)
    Posts
    434
    Quote Originally Posted by Terr
    Suggestion: Use Apache's "AddHandler" functionality so that all ".phpniggles" files are "handled" by your own PHP script. That script can then make sure that the header and footer are spit out appropriately instead of you having to put them at the very beginning and very end of every file, etc.

    VERY useful if anybody besides you might edit the file and accidentally drop an include(), put content outside the middle, etc.

    I don't quite get your point here. I regularly put php includes in the middle of files mixed in with content without issue.
    If the world doesn't stop annoying me I will name my kids ";DROP DATABASE;" and get revenge.

  8. #18
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    I don't mean includes in the content of the file, but the header and footer. Stuff which MUST be at the start or end.

    By using Addhandler and a custom extension, each page only needs to have content data within it, and you don't need header/footer includes. Whenever the page is accessed, the handler script is actually called with the page path as an argument. Then the handler script can print the header, print() or include() the contents of the page, and then print the footer.
    [HvC]Terr: L33T Technical Proficiency

  9. #19
    So do you mean, that instead of starting each page with

    session_start();
    $_POST = array_merge($_POST, $_GET);

    I can write a handler which automatically puts them at the top of each page?

    Cheers,
    Niggles

  10. #20
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    Quote Originally Posted by niggles
    So do you mean, that instead of starting each page with

    session_start();
    $_POST = array_merge($_POST, $_GET);

    I can write a handler which automatically puts them at the top of each page?
    Basically. In an .htaccess file
    Code:
    Action handlemystuff /handler.php
    AddHandler handlemystuff .myext
    DirectoryIndex index.myext index.php index.html index.htm
    Then create index.myext:
    HTML Code:
    This is an index!
    <?php print("One plus one is :".(1+1)); ?>
    Then, in /handler.php:
    HTML Code:
    <?php
    $file = $_SERVER['PATH_INFO'];
    $path = $_SERVER['DOCUMENT_ROOT'].$file;
    session_start();
    $_POST = array_merge($_POST, $_GET);
    
    include("header.php");
    include($path);
    include("footer.php");
    ?>
    You will probably want to put something in .htaccess to make it so that people can't directly visit handler.php, as well as some extra checks (realpath() + substring comparison) to make sure that nobody is trying to pass you a PATH_INFO value which isn't in the right directories.

    Another benefit from this technique is that you can define another handler and another filetype, and pass in XML files which can be translated to HTML on the fly. Or you can do search-replace within the file, or set/unset various PHP variables depending on exactly where the file is located.
    Last edited by Terr; May 25th, 2007 at 04:44 AM.
    [HvC]Terr: L33T Technical Proficiency

Similar Threads

  1. Apache, PHP, MySQL with basic security settings.
    By nightcat in forum The Security Tutorials Forum
    Replies: 9
    Last Post: May 28th, 2005, 02:47 AM
  2. PHP Flaws
    By SDK in forum Web Security
    Replies: 19
    Last Post: December 20th, 2004, 05:31 PM
  3. Tutorial: Apache 2.0.49 and PHP 4.3.7!
    By Vorlin in forum Other Tutorials Forum
    Replies: 3
    Last Post: June 15th, 2004, 10:25 PM
  4. Installing Apache and PHP on Linux
    By HDD in forum Other Tutorials Forum
    Replies: 2
    Last Post: February 1st, 2004, 08:05 PM
  5. flash for website !!!!!!!!!!!!!!
    By thuongtamnhan in forum AntiOnline's General Chit Chat
    Replies: 3
    Last Post: November 1st, 2003, 03:45 PM

Posting Permissions

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