{"id":58248,"date":"2023-02-04T03:01:32","date_gmt":"2023-02-03T17:01:32","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=58248"},"modified":"2023-02-04T07:40:47","modified_gmt":"2023-02-03T21:40:47","slug":"perl-cgi-datetime-module-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/perl-cgi-datetime-module-primer-tutorial\/","title":{"rendered":"Perl CGI DateTime Module Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/cgi-bin\/hello_get.cgi\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Perl CGI DateTime Module Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/perl_datetime.jpg\" title=\"Perl CGI DateTime Module Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Perl CGI DateTime Module Primer Tutorial<\/p><\/div>\n<p>Do you remember with <a title='Perl CGI Modes of Use Primer Tutorial' href='#pcgimupt'>Perl CGI Modes of Use Primer Tutorial<\/a> how we used the Perl programming language as an alternative server language player up at the RJM Programming website?<\/p>\n<p>Well, in any case, today, we explore some Perl modules which can make that code be more useful to us.  As for how we interface to it, we&#8217;ve written a very simple HTML <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/hello_get.html_GETME\">hello_get.html<\/a> interfacer we&#8217;d like to thank <a target=_blank title='https:\/\/www.tutorialspoint.com\/perl\/perl_cgi.htm' href='https:\/\/www.tutorialspoint.com\/perl\/perl_cgi.htm'>https:\/\/www.tutorialspoint.com\/perl\/perl_cgi.htm<\/a> for &#8230;<\/p>\n<p><code><br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;hello_get ... Thanks to https:\/\/www.tutorialspoint.com\/perl\/perl_cgi.htm and https:\/\/perlmaven.com\/most-popular-perl-modules and https:\/\/www.freecodecamp.org\/news\/how-to-format-dates-in-javascript\/&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;h1&gt;hello_get.html HTML calls on hello_get.cgi Perl&lt;\/h1&gt;<br \/>\n&lt;h3&gt;RJM Programming - February, 2023&lt;\/h3&gt;<br \/>\n&lt;h3&gt;Thanks to <a target=_blank title='https:\/\/www.tutorialspoint.com\/perl\/perl_cgi.htm' href='https:\/\/www.tutorialspoint.com\/perl\/perl_cgi.htm'>https:\/\/www.tutorialspoint.com\/perl\/perl_cgi.htm<\/a> and <a target=_blank title='https:\/\/perlmaven.com\/most-popular-perl-modules' href='https:\/\/perlmaven.com\/most-popular-perl-modules'>https:\/\/perlmaven.com\/most-popular-perl-modules<\/a> and <a target=_blank title='https:\/\/www.freecodecamp.org\/news\/how-to-format-dates-in-javascript\/' href='https:\/\/www.freecodecamp.org\/news\/how-to-format-dates-in-javascript\/'>https:\/\/www.freecodecamp.org\/news\/how-to-format-dates-in-javascript\/<\/a>&lt;\/h3&gt;<br \/>\n&lt;br&gt;&lt;br&gt;<br \/>\n&lt;FORM action = \"\/cgi-bin\/hello_get.cgi\" method = \"GET\"&gt;<br \/>\n<br \/>\n   First Name: &lt;input type = \"text\" name = \"first_name\"&gt;  &lt;br&gt;<br \/>\n<br \/>\n   Last Name: &lt;input type = \"text\" name = \"last_name\"&gt;<br \/>\n   &lt;input type = \"submit\" value = \"Submit\"&gt;<br \/>\n&lt;\/FORM&gt;<br \/>\n<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; where this webpage&#8217;s HTML form&#8217;s action points to some Perl <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/hello_get.cgi_GETME\">hello_get.cgi<\/a> (up at the Apache web server, in a cgi-bin folder and with the executable permission bit set) code using the <a target=_blank title='Perl DateTime module' href='https:\/\/metacpan.org\/pod\/DateTime'>DateTime<\/a> module, and showing the user client local timezone current time compared to this RJM Programming&#8217;s server timezone current time &#8230;<\/p>\n<p><code><br \/>\n#!\/usr\/bin\/perl<br \/>\n<br \/>\nuse DateTime;<br \/>\nuse DateTime::TimeZone;<br \/>\n<br \/>\nlocal ($buffer, @pairs, $pair, $name, $value, %FORM);<br \/>\n# Read in text<br \/>\n$ENV{'REQUEST_METHOD'} =~ tr\/a-z\/A-Z\/;<br \/>\n<br \/>\nif ($ENV{'REQUEST_METHOD'} eq \"GET\") {<br \/>\n   $buffer = $ENV{'QUERY_STRING'};<br \/>\n}<br \/>\n<br \/>\n# Split information into name\/value pairs<br \/>\n@pairs = split(\/&\/, $buffer);<br \/>\n<br \/>\nforeach $pair (@pairs) {<br \/>\n   ($name, $value) = split(\/=\/, $pair);<br \/>\n   $value =~ tr\/+\/ \/;<br \/>\n   $value =~ s\/%(..)\/pack(\"C\", hex($1))\/eg;<br \/>\n   $FORM{$name} = $value;<br \/>\n}<br \/>\n<br \/>\n$first_name = $FORM{first_name};<br \/>\n$last_name  = $FORM{last_name};<br \/>\n<br \/>\n$dt = DateTime-&gt;now;    # same as ( epoch =&gt; time )<br \/>\n<br \/>\n$dttz = DateTime::TimeZone-&gt;new( name =&gt; 'local' )-&gt;name();<br \/>\n<br \/>\n$dt-&gt;set_time_zone( $dttz );<br \/>\n<br \/>\n$year  = $dt-&gt;year;<br \/>\n$month = $dt-&gt;month;        # 1-12<br \/>\n<br \/>\n$day = $dt-&gt;day;            # 1-31<br \/>\n<br \/>\n$dow = $dt-&gt;day_of_week;    # 1-7 (Monday is 1)<br \/>\n<br \/>\n$hour   = $dt-&gt;hour;        # 0-23<br \/>\n$minute = $dt-&gt;minute;      # 0-59<br \/>\n<br \/>\n$second = $dt-&gt;second;      # 0-61 (leap seconds!)<br \/>\n<br \/>\n$doy = $dt-&gt;day_of_year;    # 1-366 (leap years)<br \/>\n<br \/>\n$doq = $dt-&gt;day_of_quarter; # 1..<br \/>\n<br \/>\n$qtr = $dt-&gt;quarter;        # 1-4<br \/>\n<br \/>\n$dmy = $dt-&gt;dmy('\/');    # 06\/12\/2002<br \/>\n<br \/>\n$hms = $dt-&gt;hms;         # 14:02:29<br \/>\n<br \/>\nprint \"Content-type:text\/html\\r\\n\\r\\n\";<br \/>\nprint \"&lt;html&gt;\";<br \/>\nprint \"&lt;head&gt;\";<br \/>\nprint \"&lt;title&gt;Hello - Second CGI Program&lt;\/title&gt;\";<br \/>\nprint \"&lt;script type=text\/javascript&gt;\";<br \/>\nprint \" function loctime() { \";<br \/>\nprint \"   var qwr='' + Intl.DateTimeFormat().resolvedOptions().timeZone; \";<br \/>\nprint \"   var d = new Date(); \";<br \/>\nprint \"   d.toLocaleString('en-US', { timeZone: qwr }); \";<br \/>\nprint \"   var ns=document.getElementById('mystime').innerHTML.split(':')[2].split(' ')[0]; \";<br \/>\nprint \"   var ls=('' + d.toLocaleString()).replace(',','') + ' GMT' + d.toString().split(' GMT')[1]; \";<br \/>\nprint \"   document.getElementById('mytime').innerHTML=ls.replace(':' + ls.split(':')[2].split(' ')[0] + ' ', ':' + ns + ' '); \";<br \/>\nprint \" } \";<br \/>\nprint \"&lt;\/script&gt;\";<br \/>\nprint \"&lt;\/head&gt;\";<br \/>\nprint \"&lt;body onload=loctime();&gt;\";<br \/>\nprint \"&lt;h2 style='font-family:Courier New;'&gt;Hello $first_name $last_name &lt;br&gt;&nbsp;Local: &lt;span id=mytime&gt;&lt;\/span&gt;&lt;br&gt;Server: &lt;span id=mystime&gt;$dmy $hms&lt;\/span&gt; $dttz &lt;\/h2&gt;\";<br \/>\nprint \"&lt;br&gt;&lt;br&gt;&lt;iframe src='\/hello_get.html' style='width:100%; height:1500px;'&gt;&lt;\/iframe&gt;&lt;\/body&gt;\";<br \/>\nprint \"&lt;\/html&gt;\";<br \/>\n<br \/>\n1;<br \/>\n<\/code><\/p>\n<p>The use of the HTML iframe in the Perl (writing HTML) code means that either &#8230;<\/p>\n<ul>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/cgi-bin\/hello_get.cgi\">hello_get.cgi<\/a><\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/hello_get.html\">hello_get.html<\/a><\/li>\n<\/ul>\n<p> &#8230; can be used to get the &#8220;Perl ball&#8221; rolling.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/new-perl-cgi-modes-of-use-primer-tutorial\/'>New Perl CGI Modes of Use Primer Tutorial<\/a>.<\/p-->\n<hr>\n<p id='pcgimupt'>Previous relevant <a target=_blank title='Perl CGI Modes of Use Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/perl-cgi-modes-of-use-primer-tutorial\/'>Perl CGI Modes of Use Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/cgi-bin\/readfile.cgi?file=..\/HTMLCSS\/india_jigsaw.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Perl CGI Modes of Use Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Perl\/perl_mode.jpg\" title=\"Perl CGI Modes of Use Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Perl CGI Modes of Use Primer Tutorial<\/p><\/div>\n<p>A little while back we revisited the <i>&#8220;PHP Modes of Use&#8221;<\/i> discussion last talked about with <a target=_blank href='#pmuftt' title='PHP Modes of Use File Traverse Tutorial'>PHP Modes of Use File Traverse Tutorial<\/a> as shown below.  We&#8217;re revisiting today to show you that it doesn&#8217;t have to be only your principal server language of choice involved in this kind of thinking, but you can also talk in terms of your chosen <a target=_blank title='Common Gateway Interface information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Common_Gateway_Interface'>CGI<\/a> (Common Gateway Interface) language of choice, which happens to be Perl here at the www.rjmprogramming.com.au domain.  The other common partner of PHP as its CGI partner is Python.<\/p>\n<p>Do you recall the three modes of use we talk about?  Here they are below &#8230;<\/p>\n<ol>\n<li>web browsing &#8230; via use of a GET arguments URL<\/li>\n<li style='color:brown;'>curl (from the command line &#8230; in our case Linux, but could be Windows too)<\/li>\n<li style='color:blue;'>command line (Perl) &#8230; use the $ARGV[] array variables<\/li>\n<\/ol>\n<p>&#8230; all good? &#8230; okay, we keep those three, but with the <a target=_blank title='cURL information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/CURL'><i>curl<\/i><\/a> option would also like to show that it can be subdivided into two submodes, namely &#8230;<\/p>\n<ul>\n<li style='color:brown;'>GET mode (via URL)<\/li>\n<li style='color:brown;'>POST mode (via <i>simulated<\/i> FORM (results))<\/li>\n<\/ul>\n<p>&#8230; which is probably true of non-CGI scenarios as well, but is particularly pertinent to discussions of CGI because we generally think of the CGI language as the one POSTed to from an HTML form, but, here, hopefully, we extend your mode of thinking to the thought that <i>curl<\/i> can handle you sending in the GET mode (though that is awkward with more than one GET argument and using the <i>&amp;<\/i> syntax) or via the use of various non-default switches such as <i>-d &#8220;name1=value1 name2=value2 blah3=blahval3&#8221;<\/i> to simulate a (form) POST &#8230; pretty powerful, huh &#8230; enabling what you may have only initially thought of as a piece of code to process an HTML form, into the additional possibility of a standalone piece of code that <a target=_blank title='Linux curl command line ideas' href='http:\/\/curl.haxx.se\/docs\/manpage.html'><i>curl<\/i><\/a> can control independent of a web browser, as required.  Please note, though, for those of us who want to &#8220;do their heads in&#8221; for <a target=_blank title='Onion of the 4th Dimension' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=4th+dimension'>&#8220;Onion of the 4th Dimension&#8221;<\/a> possibilities, the PHP <a target=_blank title='PHP exec command' href='http:\/\/php.net\/manual\/en\/function.exec.php'><i>exec<\/i><\/a> command, or something like it could be used with options 3 and\/or 2a and\/or 2b to create other possibilities.<\/p>\n<p>Anyway, have a look (closely) at our tutorial <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Perl\/perl_mode.jpg\" title=\"Show picture\">picture<\/a> and our web browser mode <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/cgi-bin\/readfile.cgi?file=..\/HTMLCSS\/india_jigsaw.html\" title=\"Click picture\">live run<\/a> &#8230;<\/p>\n<p>&#8230; and have a look at the associated Perl CGI programming source code to read an *.htm* or *.txt file in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Perl\/readfile.cgi_GETME\" title=\"readfile.cgi\">readfile.cgi<\/a><\/p>\n<p>Of great help for this tutorial was <i>Perl and CGI for the World Wide Web<\/i> by Elizabeth Castro page 195 (in particular) and <a target=_blank title='cURL command line help ... thanks' href='http:\/\/superuser.com\/questions\/149329\/what-is-the-curl-command-line-syntax-to-do-a-post-request'>What is the cURL command-line syntax to do a POST request?<\/a> (for help regarding curl command line switches for POSTed data) &#8230; thanks.<\/p>\n<p>Will leave you with a recall of the discussions regarding PHP (our primary non-CGI server language of choice at www.rjmprogramming.com.au) below &#8230;<\/p>\n<hr \/>\n<p id='pmuftt'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10515' title='PHP Modes of Use File Traverse Tutorial'>PHP Modes of Use File Traverse Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/doviadir.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Modes of Use File Traverse Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/FileTraverse.jpg\" title=\"PHP Modes of Use File Traverse Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Modes of Use File Traverse Tutorial<\/p><\/div>\n<p>It&#8217;s been a while since we last visited the <i>&#8220;PHP Modes of Use&#8221;<\/i> discussion last talked about with <a target=_blank href='#cspmoupt' title='C Supervised PHP Modes of Use Primer Tutorial'>C Supervised PHP Modes of Use Primer Tutorial<\/a> as shown below.  We&#8217;re revisiting today to show you a practical application of writing PHP for those three modes of use &#8230; namely &#8230;<\/p>\n<ol>\n<li>web browsing &#8230; use a form, then post, and then access the $_POST[] variables<\/li>\n<li>curl &#8230; note how only the one $_GET[] variable is available because of trouble using &amp; on Linux command line (use of @ is a local idea &#8230; there would be many other ideas that will work)<\/li>\n<li>command line PHP &#8230; use the $argv array variables<\/li>\n<\/ol>\n<p>&#8230; so have a look at the PHP programming source code to traverse a directory&#8217;s files in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/doviadir.php_GETME\" title=\"doviadir.php\">doviadir.php<\/a> with the live &#8220;web browsing&#8221; <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/doviadir.php\" title=\"Live Run\">live run<\/a>.<\/p>\n<p>Will leave you with a recall of the discussion below &#8230;<\/p>\n<p>Recently, with our tutorial, <a target=_blank href=\"#pmoupt\" title='PHP Modes of Use Primer Tutorial'>PHP Modes of Use Primer Tutorial<\/a> as shown below, we talked about three modes of use or access for the use of PHP and today we encase all that thinking in a Mac OS X command line C program supervision framework.  You&#8217;d expect that this is possible in a command line or Intranet environment where Linux or unix (or, for that matter, Windows command line &#8230; though the code here won&#8217;t work for this one) where C can have such a close relationship to the Linux or unix kernel, that it would be able the &#8220;run the whole show&#8221; as well as the shell commands themselves can.  Today&#8217;s C has been compiled using the Xcode IDE for use with a Mac OS X operating system.<\/p>\n<p>So that&#8217;s the supervisor above.  Read, again, about &#8220;the supervised&#8221;, below &#8230;<\/p>\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:brown;'>Via <a target=_blank title='PHP information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Curl_%28programming_language%29'>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:blue;'>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:brown;'>$_SERVER[&#8216;HTTP_COOKIE&#8217;] is undefined, but a lot of the rest of $_SERVER[] variables are as above.<\/li>\n<li style='color:blue;'>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\/C\/http_vs_curl_vs_php_command_line.png\" 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 of the supervised PHP (alone), or you may want to download the supervised 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>  or you may want to download the supervisory <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/C\/main.c_GETME\" title='main.c'>main.c<\/a> as you require.<\/p>\n<p>A &#8220;stop press&#8221; to do with code above is that since the &#8220;queueing up&#8221; of this blog post a new posting is relevant, the recent <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9586\">PHP Modes of Use Follow Up Tutorial<\/a>, and that to incorporate this posting&#8217;s improvements over <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9356\">PHP Modes of Use Primer Tutorial<\/a>, you&#8217;d want to substitute all mentions of  <i>in_tra_ter_net<\/i> with <i>more_in_tra_ter_net<\/i> in the code of main.c as above.   The relevant changed PHP source code is <a target=_blank title='more_in_tra_ter_net.php' href='http:\/\/www.rjmprogramming.com.au\/PHP\/more_in_tra_ter_net.php_GETME'>more_in_tra_ter_net.php<\/a><\/p>\n<hr \/>\n<p id='cspmoupt'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9385' title='C Supervised PHP Modes of Use Primer Tutorial'>C Supervised PHP Modes of Use Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/C\/http_vs_curl_vs_php_command_line.png\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C Supervised PHP Modes of Use Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/C\/http_vs_curl_vs_php_command_line.png\" title=\"PHP Modes of Use Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C Supervised PHP Modes of Use Primer Tutorial<\/p><\/div>\n<p>Recently, with our tutorial, <a target=_blank href=\"#pmoupt\" title='PHP Modes of Use Primer Tutorial'>PHP Modes of Use Primer Tutorial<\/a> as shown below, we talked about three modes of use or access for the use of PHP and today we encase all that thinking in a Mac OS X command line C program supervision framework.  You&#8217;d expect that this is possible in a command line or Intranet environment where Linux or unix (or, for that matter, Windows command line &#8230; though the code here won&#8217;t work for this one) where C can have such a close relationship to the Linux or unix kernel, that it would be able the &#8220;run the whole show&#8221; as well as the shell commands themselves can.  Today&#8217;s C has been compiled using the Xcode IDE for use with a Mac OS X operating system.<\/p>\n<p>So that&#8217;s the supervisor above.  Read, again, about &#8220;the supervised&#8221;, below &#8230;<\/p>\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_%28programming_language%29'>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\/C\/http_vs_curl_vs_php_command_line.png\" 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 of the supervised PHP (alone), or you may want to download the supervised 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>  or you may want to download the supervisory <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/C\/main.c_GETME\" title='main.c'>main.c<\/a> as you require.<\/p>\n<p>A &#8220;stop press&#8221; to do with code above is that since the &#8220;queueing up&#8221; of this blog post a new posting is relevant, the recent <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9586\">PHP Modes of Use Follow Up Tutorial<\/a>, and that to incorporate this posting&#8217;s improvements over <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9356\">PHP Modes of Use Primer Tutorial<\/a>, you&#8217;d want to substitute all mentions of  <i>in_tra_ter_net<\/i> with <i>more_in_tra_ter_net<\/i> in the code of main.c as above.   The relevant changed PHP source code is <a target=_blank title='more_in_tra_ter_net.php' href='http:\/\/www.rjmprogramming.com.au\/PHP\/more_in_tra_ter_net.php_GETME'>more_in_tra_ter_net.php<\/a><\/p>\n<hr \/>\n<p id='pmoupt'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9356' title='PHP Modes of Use Primer Tutorial'>PHP Modes of Use Primer Tutorial<\/a> is shown below.<\/p>\n<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_%28programming_language%29'>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='#d9356' onclick='var dv=document.getElementById(\"d9356\"); 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='d9356' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\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='#d9385' onclick='var dv=document.getElementById(\"d9385\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Xcode\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d9385' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\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='#d10515' onclick='var dv=document.getElementById(\"d10515\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=curl\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d10515' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\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='#d11171' onclick='var dv=document.getElementById(\"d11171\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=CGI\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d11171' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\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='#d58248' onclick='var dv=document.getElementById(\"d58248\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/perl\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d58248' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Do you remember with Perl CGI Modes of Use Primer Tutorial how we used the Perl programming language as an alternative server language player up at the RJM Programming website? Well, in any case, today, we explore some Perl modules &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/perl-cgi-datetime-module-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":[3028,85,196,4240,212,301,302,3929,452,576,802,830,916,4021,997,1122,1693,1319,1418],"class_list":["post-58248","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-action","tag-apache","tag-cgi","tag-cgi-bin","tag-client","tag-date","tag-datetime","tag-executable","tag-form","tag-html","tag-module","tag-navigation","tag-perl","tag-permissions","tag-programming","tag-server","tag-timezone","tag-tutorial","tag-webpage"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/58248"}],"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=58248"}],"version-history":[{"count":6,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/58248\/revisions"}],"predecessor-version":[{"id":58254,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/58248\/revisions\/58254"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=58248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=58248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=58248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}