PHP Questions

Posted:
in Mac Software edited January 2014
My site is hosted by Earthlink and their installation of PHP seems to be a little ratty...I'm still learning it right now so I'm no expert. What version of PHP should I expect a good host to be running? Can I install PHP in one of my own directories? I figure not, it seems like a server thing to interpret .php3 file extensions - so I assume it runs to a "main" installation of PHP.



I'm asking because the code



print ("Hello World");



won't work...the Earthlink PHP wants the parenthesis removed.



I just get the feeling that it's a pissy install.



«1

Comments

  • Reply 1 of 22
    Quote:

    Originally posted by drewprops



    I'm asking because the code



    print ("Hello World");



    won't work...the Earthlink PHP wants the parenthesis removed.



    I just get the feeling that it's a pissy install.







    This doesn't neccessarily have anything to do with your ISP's PHP installation. If your site is hosted on a Unix machine, the problem might be that you've created your PHP script on a Macintosh.

    Line endings on the Mac are different than line endings on Unix machines, sometimes this causes trouble. If you're using BBEdit you can set the line ending format when clicking "Options" in the "Save File" dialog box.



    Greetings,

    Daniel
  • Reply 2 of 22
    xoolxool Posts: 2,460member
    Did you enclose the code within php tags?



    Like this:

    Code:




    <?php

    echo("Hello World");

    ?>









    Your linebreak format shouldn't matter except when it comes to strings -- although error reporting usually keys off unix line numbers. The PHP parser ignores whitespace when it comes to code.
  • Reply 3 of 22
    Moving to Software.
  • Reply 4 of 22
    drewpropsdrewprops Posts: 2,321member
    dingo kidneys, it's got to be the line endings boys.



    Dangit, I hit this problem before when I was doing something else on the site....installing bloxsom I think it was. Should've thought of that already. Okay, time to break out Haxial and try again....and I might want to get BBEdit, about time I tried it again.



    Those machines are running UNIX methinks....



    Thanks team!





    Update: Yes, of course it was the line endings. I'll never fail to forget the crucial technical step at just the wrong time...
  • Reply 5 of 22
    Line endings won't play any role unless you are parsing a .txt file (like taking a .txt file and putting it into a database). Line endings will affect how that code looks when opened in an editor on another platform, but line endings aren't parsed by PHP at all - it doesn't care if you put all your code on one line or on a million...



    What version of PHP are they running? You can put up a page to show you:



    <?php

    phpinfo();

    ?>



    That will give you all kinds of beefy information about your PHP install...



    If there is a problem with your code, typically the resulting page will display an error message (unless they have error reporting turned off, which no hosts I have ever seen do). Do you get an error message?



    There technically is nothing wrong with your code, but I personally never use the parenthesis (I typically use echo too, but that is a different story).



    print function



    EDIT: your php file is a plain text file right? Oh - looks like you solved the issue?
  • Reply 6 of 22
    torifiletorifile Posts: 4,024member
    Quote:

    Originally posted by drewprops

    dingo kidneys, it's got to be the line endings boys.



    Dangit, I hit this problem before when I was doing something else on the site....installing bloxsom I think it was. Should've thought of that already. Okay, time to break out Haxial and try again....and I might want to get BBEdit, about time I tried it again.



    Those machines are running UNIX methinks....



    Thanks team!





    Update: Yes, of course it was the line endings. I'll never fail to forget the crucial technical step at just the wrong time...




    drew, I know what you mean. I'm sitting staring at thousands of lines of code and I always forget that one semicolon or curly bracket that screws everything up and I change it all only to find out that I'm just careless as opposed to an idiot.
  • Reply 7 of 22
    drewpropsdrewprops Posts: 2,321member
    I did solve it...and honestly it WAS the line-endings! Don't ask me why, I just shake the voodoo rattle when they tell me to!



    Down below I've listed a little of the info about the version of PHP that Earthlink has us on at present, note that the first value is the Master Value, the second value is the Local Value. So how old is this car we're driving?







    PHP Version 3.0.18



    arg_separator

    _&

    _&



    asp_tags

    1

    1



    auto_prepend_file

    _

    _



    auto_append_file

    _

    _



    browscap

    _/ms/svc/php/conf/extra/browscap.ini

    _/ms/svc/php/conf/extra/browscap.ini



    cgi_ext

    _none

    _none



    debugger.host

    _none

    _none



    debugger.port

    0

    0



    define_syslog_variables

    0

    0



    display_errors

    1

    1



    doc_root





    enable_dl

    1

    1



    engine

    1

    1



    error_log

    _/tmp/php3.err

    _/tmp/php3.err



    error_append_string

    _none

    _none



    error_prepend_string

    _none

    _none



    error_reporting

    7

    7



    extension_dir

    _./

    _./



    gpc_order

    _GPC

    _GPC



    ignore_user_abort

    0

    0



    include_path

    _

    _



    isapi_ext

    _none

    _none



    last_modified

    0

    0



    log_errors

    1

    1



    max execution time

    3600

    3600



    magic_quotes_gpc

    1

    1



    magic_quotes_runtime

    1

    1



    magic_quotes_sybase

    0

    0



    memory limit

    8388608

    8388608



    nsapi_ext

    _none

    _none



    open_basedir

    _none

    _none



    precision

    14

    14



    safe_mode

    1

    1



    safe_mode_exec_dir

    _/usr/local/bin

    _/usr/local/bin



    sendmail_from

    _none

    _none



    sendmail_path

    _/usr/sbin/sendmail -t

    _/usr/sbin/sendmail -t



    short_open_tag

    1

    1



    smtp

    _localhost

    _localhost



    sql_safe_mode

    0

    0



    track_errors

    1

    1



    track_vars

    1

    1



    upload_max_filesize

    2097152

    2097152



    upload_tmp_dir

    _none

    _none



    user_dir

    _none

    _none



    warn_plus_overloading

    0

    0



    xbithack

    0

    0



    browscap

    _/ms/svc/php/conf/extra/browscap.ini

    _/ms/svc/php/conf/extra/browscap.ini



    y2k_compliance

    1

    1



    highlight_comment

    _#FF8000

    _#FF8000



    highlight_default

    _#0000BB

    _#0000BB



    highlight_html

    _#000000

    _#000000



    highlight_string

    _#DD0000

    _#DD0000



    highlight_bg

    _#FFFFFF

    _#FFFFFF



    highlight_keyword

    _#007700

    _#007700
  • Reply 8 of 22
    Quote:

    Originally posted by drewprops

    PHP Version 3.0.18



    PHP 3.0??? Hmm... Earthlink must have been outta touch with the rest of the world since the middle ages... Well, actually, that version is about three years old. The current one is PHP 4.3.4 and version 5 is in the final stages of development...
  • Reply 9 of 22
    I am not surprised Earthlink is behind the times, but it is surprising they haven't at least upgraded to PHP 4. Register Globals being on by default in version 3 is a huge security issue for PHP based apps...



    Leave it to the big boys...
  • Reply 10 of 22
    drewpropsdrewprops Posts: 2,321member
    Yes, they're on their asses as far as I can tell. The documentation for their customers is so slack that it sucks. Here's what they have to say about PHP....getting the link....okay check THIS out!!



    sad really





    I wonder, does PHP 4.x have a special extension? Like .php3 does? What if I change my call to .php4?



    Going to try that now....





    But in the meantime, if anybody knows the answer....well, you know.





    Edit: Dumbasses. They don't even tell customers that they have v.4.x running ANYWHERE in their documentation. So yes, the .php4 extension worked. We're running:



    PHP Version 4.1.2



    So good. I just wish they'd update their docs for crying out loud.
  • Reply 11 of 22
    It's good to learn on PHP4 because of the register globals thing I mentioned (deals with variable scope). If you learn, and code, to PHP3, and then move to php4 it is nearly inevitable your app is going to break and you are going to have to go back through and fix your variable scope.



    For more info you can look here:



    register globals



    and



    predefined variables
  • Reply 12 of 22
    torifiletorifile Posts: 4,024member
    Quote:

    Originally posted by The Pie Man

    It's good to learn on PHP4 because of the register globals thing I mentioned (deals with variable scope). If you learn, and code, to PHP3, and then move to php4 it is nearly inevitable your app is going to break and you are going to have to go back through and fix your variable scope.



    For more info you can look here:



    register globals



    and



    predefined variables




    IIRC, register globals was on through version 4.0.6 (maybe longer). When I updated to 4.3.2 all my scripts were broken because the php book I learned with (wrox "Beginning PHP4") didn't even mention the register globals thing. Luckily it was easy to fix but was I freaked out when things stopped working.
  • Reply 13 of 22
    drewpropsdrewprops Posts: 2,321member
    I will most assuredly do everything in PHP4!



    I've been going over a couple of good tutorials that used to be hosted on hotwired's web monkey site....they're now on the lycos servers (although some of the links are broken).



    My big challenge will be to figure out how best to use PHP to my advantage with my own website. I smell the potential, I just need to visualize how to make it work for me.



    If anybody can point me toward some other practical examples of how to use PHP it would be appreciated~
  • Reply 14 of 22
    xoolxool Posts: 2,460member
    One can use PHP to dynamically build pages, generally taking a standard set of templates and populating them with content. A simple example is displaying the current time without using javascripts. A more complex example is handling news posts to your website. For news, if you add a new article, you're not manually managing the site after every update. PHP outputs the news articles in the proper format and handles other tasks like pagination. Other features, like a news archive, could be handled automatically and more. The content can be populated from a database, a text file, or reside inline with your PHP code.



    At my company, we have a large number of high profile sites running on PHP. I have seen all types of systems implemented in PHP, ranging from simple scripts to large-scale OOP-based frameworks. PHP is fairly capable and can do most of things you could want it to do.



    You could come up with a number of things to do, each of which could be implemented in thousands of ways. Figuring out the best way to do something is perhaps easier said than done -- but this is not new.



    Anyhow, here's a short list of examples, general and specific:

    * Output the current date/time to your web pages

    * Add basic customization and/or personalization of pages based on user information (ie: arranging elements ala Yahoo's home page or displaying "Welcome Xool!")

    * Securing access to pages

    * Automatic handling of content: page layout, editing, searching, etc. (Don't get me started!)

    * Build interactive systems, such as message boards or other community-driven features

    * Build an online store, processing CC sales and sending out merchandise

    * Power your own Porn site!

    * Run a Mac rumor site

    * Fight evil



    Some things you can't do with PHP:

    * Grow vegetables

    * Milk snakes

    * Bring all the boys to the yard (well maybe, but expect a lot of nerds to come runnin' myself included)

    * Birth babies
  • Reply 15 of 22
    drewpropsdrewprops Posts: 2,321member
    Yes I'm very excited about the ability it will give me to essentially drop in text files that could be propagated into entire pages. Actually getting dirty in the code is what I need to do right now.



    Not that anybody should make me their special project, but if anyone can answer the following question(s) I'd be grateful. I've encountered some curious things in an example file found on the WebMonkey example...specifically these few lines of code:





    # root should be like "/brad/php/example3"

    # get directory containing current script

    $root = getenv("SCRIPT_NAME");

    # get rid of everything after the current directory, which I just so happen

    # to know is '/meta'

    $root = substr($root,0,strpos($root,"/meta"));



    #print "<p>root=[$root]</p>\

    ";



    # docroot should be like "/hot/bab/brad/php/example3"

    $docroot = getenv("DOCUMENT_ROOT").$root;



    #print "<p>docroot=[$docroot]</p>\

    ";



    The full PHP script can be found HERE.



    OKAY!

    First off, getenv("SCRIPT_NAME") doesn't give me a filepath as they describe in the preceding comment tag, no, it gives me the root location of the script name, that is:



    /root-cgi/php4







    Shouldn't I really be doing a : getenv("REQUEST_URI") instead? If I do THAT then I get a path back to the root of my web directory. That seems like what I'm supposed to be looking for...





    Again, the full PHP script can be found HERE. This comes from page six of the Web Monkey tutorial!
  • Reply 16 of 22
    drewpropsdrewprops Posts: 2,321member
    I sat on the floor of the bookstore today and flipped through about ten different books. I ended up buying the O'Reilly book on PHP today because it didn't try to make me build a messageboard or a shopping cart....it just discussed what the commands do.



    Any other must-have PHP publications?
  • Reply 17 of 22
    xoolxool Posts: 2,460member
    O'Reilly was a good choice. If you plan to do any real work, the MySQL book is also a good idea. However, the online documentation for both MySQL and PHP is quite good. Even though I have these books (and others!) my primary references are mysql.com and php.net.



    My question is what level programmer are you? If you are a novice I can recommend one thing... if an old pro, I could recommend something else.
  • Reply 18 of 22
    drewpropsdrewprops Posts: 2,321member
    I'm a rusty programmer is what I am, but for the sake of this . The only languages I know are PASCAL, FORTRAN and BASIC and the last time I used them was back in the late 80's. I can understand code if given enough time to "see" what's happening, coding transcends any particular language (unless you're doing iterative loops and such). I've coded HTML, am teaching myself to "think in CSS" and PHP looks easy to comprehend, all I think I really need to do is to figure out what I want to do then work backwards from there. The PHP.net site IS probably my greatest ally.



    What I'm trying to do is to go back through my existing site and qualify and categorize my content so that I can re-think how to present the data. I'm probably going to integrate movable type into my new site because I like some of the features I see there. I may integrate the GALLERY software for displaying my portfolio, although I'm considering going with a Flash presentation too...a bit more spiffy and slick looking.



    So, right now, I'm at the stage where I'm reverse-engineering some of those old tutorials (as mentioned above) to see how things work....
  • Reply 19 of 22
    torifiletorifile Posts: 4,024member
    Quote:

    Originally posted by drewprops

    Any other must-have PHP publications?



    I like "MySQL/PHP Applications" (or something like that. It's in my computer room and I'm lazy). It's more applied than you probably want but you can find the basics online.



    Personally, I'm using php/mysql for running my site. I'm doing a study on the effectiveness of a web-based intervention. It does user tracking, data collection, messaging, etc. All content is in a database and the pages are all based on a template that gets filled in with the relevant data. It's a nice mix of php, html, javascript and css. It wouldn't be possible with any other language.
  • Reply 20 of 22
    Remember if you have any PHP questions just IM me, I am more than happy to help out. Plus it keeps me on my toes with my PHP.
Sign In or Register to comment.