{"id":9356,"date":"2014-09-04T05:05:14","date_gmt":"2014-09-03T19:05:14","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9356"},"modified":"2014-09-04T05:05:14","modified_gmt":"2014-09-03T19:05:14","slug":"php-modes-of-use-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-modes-of-use-primer-tutorial\/","title":{"rendered":"PHP Modes of Use Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/http_vs_curl_vs_php_command_line.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Modes of Use Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/http_vs_curl_vs_php_command_line.jpg\" title=\"PHP Modes of Use Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Modes of Use Primer Tutorial<\/p><\/div>\n<p><a target=_blank title='PHP information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/PHP'>PHP<\/a> is a very flexible programming language.  It is probably best known as a server-side language called by a web browser using the http transport layer (ie. web browsing, or &#8220;surfing the net&#8221;).  Let&#8217;s list three modes of use of PHP below:<\/p>\n<ol>\n<li>Via http transport layer (ie. web browsing, or &#8220;surfing the net&#8221;) in an <a target=_blank title='Internet information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Internet'>Internet<\/a> mode of use (eg: http:\/\/localhost:8888\/in_tra_ter_net.php?SERVER_NAME=localhost) in address bar of a web browser<\/li>\n<li style='color:blue;'>Via <a target=_blank title='PHP information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/CURL'>curl<\/a> in an Internet mode of use (eg. curl http:\/\/localhost:8888\/in_tra_ter_net.php?SERVER_NAME=localhost) at Linux or unix or Windows command line to default output (and you can redirect as required via &gt; <i>outfile<\/i> or &gt;&gt; <i>outfile<\/i> or 2&gt; <i>errfile<\/i> or 2&gt;&gt; <i>errfile<\/i>)<\/li>\n<li style='color:brown;'>Via command line PHP in Linux or unix or Windows command line in a command or <a target=_blank title='Intranet information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Intranet'>Intranet<\/a> mode of use (eg. php in_tra_ter_net.php SERVER_NAME=localhost) at a Linux or unix or Windows command line (where the PHP code has been placed, in our example (ie. it is not a URL, but is a file specification of your (Intranet) server)) to default output (or you can redirect as required via &gt; <i>outfile<\/i> or &gt;&gt; <i>outfile<\/i> or 2&gt; <i>errfile<\/i> or 2&gt;&gt; <i>errfile<\/i>)<\/li>\n<\/ol>\n<p>Does it matter how the PHP is accessed?  Well, yes, it does &#8230; sometimes, but not if the code is restricted to a particular mode of usage (but part of what this tutorial is about is to get across how flexible and powerful PHP can be).  With the last option above, lots of <a target=_blank title='PHP $_SERVER[] variables' href='http:\/\/au2.php.net\/reserved.variables.server.php'>$_SERVER[]<\/a> variables are undefined, for example.<\/p>\n<ol>\n<li>$_SERVER[&#8216;HTTP_COOKIE&#8217;] is defined, unlike with curl usage (this seems to be a possibility as a way to detect curl usage).  Most $_SERVER[] variables are defined, but $argv[] array is not.<\/li>\n<li style='color:blue;'>$_SERVER[&#8216;HTTP_COOKIE&#8217;] is undefined, but a lot of the rest of $_SERVER[] variables are as above.<\/li>\n<li style='color:brown;'>Lots of $_SERVER[] variables are undefined, with the exception of $_SERVER[&#8216;SCRIPT_FILENAME&#8217;] which may help you with Intranet application usage.  You cannot enter $_GET[] arguments (on the command line (ie. you will get a syntax error if you try)) so these are undefined, but $argv[] array can be used in that awkward way shown, so that $argv[1] can be arranged to be a lot like $_SERVER[&#8216;QUERY_STRING&#8217;] (ie. the bits after ? in a URL).<\/li>\n<\/ol>\n<p>So, maybe you have the one mode of use in mind, but you need to think a bit to support all the modes of use, if they are all to have a role with the PHP you write, because, despite these differences it is good to use $_SERVER[] and $_GET[] and $_POST[] and $_SESSION[] and $argv[] and whatever else in terms of variable information PHP offers in terms of attempting to write generic code.<\/p>\n<p>Hope you get something out of today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/http_vs_curl_vs_php_command_line.jpg\" title='Click picture'>discussion<\/a> of our Mac OS X MAMP Apache local Web server environment example (hence the <i>http:\/\/localhost:8888\/<\/i> you see in the URLs above), but please bear in mind that there would be other modes of use once you think of other client HTML element ways of accessing PHP (all a lot like the &#8220;web browsing&#8221; of above) or other possibilities within PHP code itself via PHP commands <a target=_blank title='PHP exec' href='http:\/\/php.net\/manual\/en\/function.exec.php'><i>exec<\/i><\/a> and <a target=_blank title='PHP file_get_contents' href='http:\/\/php.net\/manual\/en\/function.file-get-contents.php'><i>file_get_contents<\/i><\/a> the latter of which can be very useful during Intranet usage where there is no <i>curl<\/i> available, perhaps.  Instead of curl you could use <a target=_blank title='wget' href='http:\/\/www.gnu.org\/s\/wget\/'>wget<\/a> as another approach.<\/p>\n<p>You may want to see a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/in_tra_ter_net.php\" title='Live Run'>live run (web browsing)<\/a> here at the rjmprogramming.com.au domain or you may want to download the PHP programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/in_tra_ter_net.php_GETME\" title='in_tra_ter_net.php'>in_tra_ter_net.php<\/a> as you require.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d5435' onclick='var dv=document.getElementById(\"d5435\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=PHP\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5435' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>PHP is a very flexible programming language. It is probably best known as a server-side language called by a web browser using the http transport layer (ie. web browsing, or &#8220;surfing the net&#8221;). Let&#8217;s list three modes of use of &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-modes-of-use-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[213,234,284,581,621,624,707,725,744,932,997,1319,1424],"class_list":["post-9356","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-clientserver","tag-command-line","tag-curl","tag-http","tag-internet","tag-intranet","tag-linux","tag-mac-os-x","tag-mamp","tag-php","tag-programming","tag-tutorial","tag-wget"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/9356"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=9356"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/9356\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=9356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=9356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=9356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}