{"id":8368,"date":"2014-07-07T05:01:44","date_gmt":"2014-07-06T19:01:44","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=8368"},"modified":"2014-07-07T05:01:44","modified_gmt":"2014-07-06T19:01:44","slug":"php-wheres-wally-test-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-wheres-wally-test-primer-tutorial\/","title":{"rendered":"PHP Where is Wally Test Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/Todays_List.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Where's Wally Test Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/Todays_List.jpg\" title=\"PHP Where's Wally Test Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">PHP Where's Wally Test Primer Tutorial<\/p><\/div>\n<p>Today, was going to show you comparisons of PHP[\/HTML] versus Javascript\/Ajax\/HTML versus Javascript\/HTML methodologies to have a password protected report only reported, securely (or not), to interested parties &#8230; ie. bits of talk regarding &#8220;security&#8221; &#8230; but today there is no encryption\/decryption talk, and we have decided to just stick to PHP, and later on we may visit some other ideas.   Today we extend on the <a title='Files Since Primer Tutorial' href='#fspt'>Files Since Primer Tutorial<\/a> as shown below, for inspiration regarding what might be interesting as subject matter to report on.  We aim today to show some methods to address the most obvious weakness of not involving server-side PHP nor Ajax techniques, where if the user uses the browser&#8217;s View->Page Source they can discover your password fairly easily.   It should be noted that we do not claim that somebody won&#8217;t crack this method via other means, but we can say that it helps with the View->Page Source level of security.<\/p>\n<p>So let&#8217;s set the scene &#8230; we want a report about *.htm* and *.php files that have changed over the last five days on our local Apache MAMP local web server &#8230; and we want an email and an alternative means of viewing &#8230; why? &#8230; because not every Linux web server has <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Mailx' title='Unix\/Linux mailx information from Wikipedia ... thanks'><i>mailx<\/i><\/a> installed (as does my local MAMP web server&#8217;s laptop).<\/p>\n<p>Take a look at the (Mac laptop Terminal application Linux Bash environment&#8217;s) Korn shell script (that in reality you would not want to place within view of your web server&#8217;s directories (ie. the web server viewable directories come off parent described in PHP by <a target=_blank title='PHP $_SERVER[\"DOCUMENT_ROOT\"]' href='http:\/\/www.php.net\/manual\/en\/reserved.variables.server.php'>$_SERVER[&#8220;DOCUMENT_ROOT&#8221;]<\/a> so place this file outside these directories) &#8230; but we put there for you to take a took at) that you could call <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todays_list.ksh_GETME' title='todays_list.ksh'>todays_list.ksh<\/a> (and you could execute via crontab or interactively via .\/todays_list.ksh (if execute bits set via chmod) or via ksh todays_list.ksh (if not)) which writes out the todaylist.php of below (please note that if you have mailx installed on your web server &#8230; see the orange lines on picture above &#8230; you may not want to perform any of the PHP or HTML below, because an emailed report will suffice).<\/p>\n<p>The PHP programming source code you could call <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todaylist.php_GETME' title='todaylist.php'>todaylist.php<\/a> (produced via todays_list.ksh as above), and hopefully you see that it caters for $_GET[&#8216;pw&#8217;] parameter on a web browser&#8217;s address bar ( ie. <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todaylist.php?pw=Where%27s%20Wally' title='http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todaylist.php?pw=Where%27s%20Wally'>http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todaylist.php?pw=Where%27s%20Wally<\/a> (a variation of this link could be your Home Page on your favourite browser, to receive information on the report each time you reopen that web browser) ) or via a supervisory HTML file&#8217;s form method=&#8217;POST&#8217; action=&#8217;todaylist.php&#8217; submission scenario (as you see below).<\/p>\n<p>The HTML supervisory programming source code you could call <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todaylist.html_GETME' title='todaylist.html'>todaylist.html<\/a> (statically and separately (to the use of the Korn shell script) created by you), and supervising todaylist.php above via the $_POST[&#8216;pw&#8217;]  form method=&#8217;POST&#8217; action=&#8217;todaylist.php&#8217; submission scenario.<\/p>\n<p>So, the bottom line is this &#8230; have hinted that &#8220;Where&#8217;s Wally&#8221; is the likely password.  Forget the Korn shell (it will be in an invisible place, remember), can you find the words &#8220;Where&#8217;s Wally&#8221; anywhere else within the (first two types of) usage of the software below, either with:<\/p>\n<ul>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todaylist.html\">POST method<\/a> (preferred, as URL will never show &#8220;Where&#8217;s Wally&#8221;) &#8230; follow the red arrows in picture above &#8230; or &#8230; <\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todaylist.php\">GET method<\/a> (usage of person (not in the know) sniffing around, hopefully, unsuccessfully) &#8230;  vs &#8230; <\/li>\n<li><a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/todaylist.php?pw=Where%27s%20Wally'>GET method<\/a> (successful user usage of person in the know) &#8230; follow the green arrows in picture above     ?<\/li>\n<\/ul>\n<p>Hope I haven&#8217;t made this seem too complex, because once you get into PHP, as a server-side language (like ASP.Net as well), these things become much easier and straightforward (to me I prefer PHP to Ajax methodologies, but there will be many who disagree), though with this straightforwardness comes the trade-off that you can give away information you rather would not give away &#8230; the dilemma of <i>security<\/i> in today&#8217;s online world.<\/p>\n<p>For your leisure activities after your fastidious <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Security\/Todays_List.jpg\" title='Click picture'>studies<\/a> &#8230; <a target=_blank title=\"Where's Wally\" href='http:\/\/www.youtube.com\/watch?v=ZEi0dBt3Sgs'>here<\/a> &#8230; hope to see you next time.<\/p>\n<hr \/>\n<p id='fspt'>Previous relevant <a target=_blank title='Files Since Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=874'>Files Since 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\/Windows\/FilesSince\/Files_Since.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Files Since Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Windows\/FilesSince\/Files_Since.jpg\" title=\"Files Since Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Files Since Primer Tutorial<\/p><\/div>\n<p>A while ago we spoke of the Linux commands find and locate in <a href=\"#lfalfpt\">Linux Find and\/or Locate Files\/Directories Primer Tutorial<\/a> as shown below.  After that you may have been thinking &#8220;That&#8217;s it!  No more carrying on about directory listings and stuff!&#8221; &#8230; and we say &#8230; but on a practical level how can this knowledge be set to good use?<\/p>\n<p>With that in mind, today, we do a tutorial called &#8220;Files Since&#8221; (and just concentrate on command line work &#8230; there may well be Mac Finder and\/or Windows Explorer solutions to this problem, but want to stick to command line, for today), because it is easy to get <strike>sidetracted<\/strike> sidetracked these days and forget what you&#8217;ve been doing, so today for both Mac and Windows we show a scenario of (finding files that):<\/p>\n<ul>\n<li>are HTML<\/li>\n<li>have been worked on over the last seven days<\/li>\n<li>from all directories and subdirectories off where we are now (in relevant command line environment)<\/li>\n<\/ul>\n<p>Obviously, if you are asleep now, you&#8217;ll continue to be asleep, and you can sleep through the next bit just as well.<\/p>\n<p>But if you are still here, this scenario is a doddle for Mac (via Bash environment find command via Terminal application).  However, believe it or not, it is not straightforward in a Windows (DOS command line) environment, depending on how user-friendly you want the information to be &#8230; let me explain &#8230; DOS command line (out of the box) can do a listing sorted by date (descending) of the last file write date for all the subdirectories, but, without some tailoring it can&#8217;t cut off the report and not mention superfluous files to your designated date range of interest &#8230; for us, 7 days.<\/p>\n<p>You might ask, &#8220;How come?&#8221; &#8230; and that is a good question &#8230; but wasting time &#8230; so why don&#8217;t we create a hybrid DOS\/Linux-find-equivalent-of-mtime-switch scenario.  What is meant by this is that Windows\/DOS does 99% of what anybody wants, and that is good (thanks), but why not try to add on the bit of Linux find (its -mtime -7d (for our case) &#8230; (just the d suboption will be assumed)) cute functionality into our Windows\/DOS world &#8230; with help from <a target=_blank href='http:\/\/www.experts-exchange.com\/OS\/Microsoft_Operating_Systems\/MS_DOS\/A_10774-Advanced-Batch-File-Programming-YESTERDAY-BAT.html' title='Get date of yesterday in DOS Batch'>here<\/a> (get yesterday&#8217;s date in DOS batch &#8230; thanks) and <a target=_blank title='Brilliant DOS batch string functionality web page ... thanks' href='http:\/\/www.dostips.com\/DtTipsStringOperations.php'>here<\/a> (brilliant DOS batch string functionality web page &#8230; thanks) this became possible and we would like you to try <a target=_blank title='mydir.bat' href='http:\/\/www.rjmprogramming.com.au\/Windows\/FilesSince\/mydir.bat_GETME'>mydir.bat<\/a> should you wish to try it out.  Where should you place mydir.bat in order to try it out on Windows?  Well, if &#8220;mydir&#8221; as a command line command, means nothing, at present on your system, it would be best of all to place mydir.bat somewhere in the path (the directories of which can be gleaned from <i>echo %PATH%<\/i>), but you may not want it that public, and so, just place mydir.bat in the root directory of interest you want information about, if this is your case &#8230; in either scenario mydir.bat works after you have used <i>cd [blah blah]<\/i> to get to the root directory of your interest.  For our example scenarios today the [blah blah] equated to the root directories for the local Apache web server of interest &#8230; for Windows the root directory of <a target=_blank href='http:\/\/www.easyphp.org\/' title='EasyPHP home page'>EasyPHP<\/a> ( &#8220;c:Program FilesEasyPHP-12.1www&#8221; ) and for Mac the root directory of <a target=_blank href='http:\/\/www.mamp.info\/' title='MAMP home page'>MAMP<\/a> ( \/Applications\/MAMP\/htdocs ).   More on this happens on this blog at <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4112' title='Generic web server tutorial'>Cassini++ WebServer Primer Tutorial<\/a>.<\/p>\n<p>So, in summary, try this tutorial for ideas about command line environment solutions to the &#8220;Files since &#8230;&#8221; scenario that many of us often face when using computers &#8230; our commands ended up:<\/p>\n<ul>\n<li>find . -name &#8220;*.htm*&#8221; -mtime -7 2&gt; \/dev\/null        # Mac (via Linux Bash via Terminal)  NB. Some environments would ask for switch -mtime -7d<\/li>\n<li>mydir *.htm* \/s \/t:w \/o:-d \/m:-7       rem  Windows (via DOS command line)<\/li>\n<\/li>\n<hr \/>\n<p id='lfalfpt'>Previous relevant <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7067\">Linux Find and\/or Locate Files\/Directories 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\/Linux\/locate\/LocateFind_Linux.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux Find and\/or Locate Files\/Directories Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/locate\/LocateFind_Linux.jpg\" title=\"Linux Find and\/or Locate Files\/Directories Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Linux Find and\/or Locate Files\/Directories Primer Tutorial<\/p><\/div>\n<p>Linux (or Unix) servers have two really useful commands which help the user find files and\/or directories &#8230; <a target=_blank title='Linux\/unix locate command help from Computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/ulocate.htm'>locate<\/a> and <a target=_blank title='Linux\/unix find command help from Computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/ufind.htm'>find<\/a>.  Doubt there are many people out there who have not mislaid a computer file at some time or other.   The GUI options are there, such as Windows Explorer and Mac Finder, but you tend to think, with these, of the one area or folder to search (mind you both are capable of better), whereas you often face the dilemma of having no idea where the file is.   The GUIs can help here, but find, for myself, that I always jump to the command line for this, with Windows command line DIR C: [filespec] \/s or the Linux\/Unix commands for today&#8217;s tutorial &#8230; locate and find.<\/p>\n<p>So why confuse things with two choices?   Well, locate is fast, once set up, because it sets up its own &#8220;database&#8221; of previous knowledge, and so can pluck out whatever you want really fast from then on, once you use a &#8220;<a target=_blank title='Linux\/unix sudo command help from Computerhope ... thanks.' href='http:\/\/www.computerhope.com\/unix\/sudo.htm'>sudo<\/a>&#8221; command to set up locate for future use.<\/p>\n<p>The strength of the Linux\/Unix find command are its switches like &#8220;-type ?&#8221; to define what type of file to find, and the way you can use &#8220;exec&#8221; in a piped scenario, to add more functionality.<\/p>\n<p>So some words about the syntax (and for this, found <i>Linux<\/i> by Steve Oualline and Eric Foster-Johnson (pp 72-73) an excellent source) where you can hover or click for further information:<\/p>\n<ul>\n<script>function showt(ospan) {\n  ospan.style.backgroundColor = 'yellow';\n  alert(ospan.title);\n  ospan.style.backgroundColor = '';\n}<\/script><\/p>\n<li><span id=\"a1\" title=\"The locate command in Linux or unix.\" onclick=\"showt(this);\">locate<\/span> <span id=\"a2\" title=\"File name or file name fragment to look for.\" onclick=\"showt(this);\">gimp<\/span> <span id=\"a3\" title=\"Pipe operator in Linux or unix.\" onclick=\"showt(this);\">|<\/span> <span id=\"a4\" title=\"Pipe to more command for 13 lines at a time.\" onclick=\"showt(this);\">more -y 13<\/span><\/li>\n<li><span id=\"b1\" title=\"The find command in Linux or unix.\" onclick=\"showt(this);\">find<\/span> <span id=\"b2\" title=\"This is start directory of search.\" onclick=\"showt(this);\">\/<\/span> <span id=\"b3\" title=\"Find command searches for all files satisfying *gimp* filespec.\" onclick=\"showt(this);\">-name &#8220;*gimp*&#8221;<\/span> <span id=\"b4\" title=\"Filter search to files of type f (file) so that directores and special files are excluded.\" onclick=\"showt(this);\">-type f<\/span> <span id=\"b5\" title=\"What to do when file is found - print it to standard output..\" onclick=\"showt(this);\">-print<\/span> <span id=\"b6\" title=\"Ignore outputting any errors found performing this command.\" onclick=\"showt(this);\">2> \/dev\/null<\/span> <span id=\"by\" title=\"Pipe operator in Linux or unix.\" onclick=\"showt(this);\">| <\/span> <span id=\"b8\" title=\"Pipe to more command for 13 lines at a time.\" onclick=\"showt(this);\">more -y 13<\/span><\/li>\n<li><span id=\"c1\" title=\"The find command in Linux or unix.\" onclick=\"showt(this);\">find<\/span> <span id=\"c2\" title=\"This is start directory of search.\" onclick=\"showt(this);\">$HOME\/Documents<\/span> <span id=\"c3\" title=\"Find command searches for all files satisfying *.htm* filespec.\" onclick=\"showt(this);\">-name &#8220;*.htm*&#8221;<\/span> <span id=\"c4\" title=\"Filter search to files of type f (file) so that directores and special files are excluded.\" onclick=\"showt(this);\">-type f<\/span> <span id=\"c5\" title=\"Use to execute command on the file.\" onclick=\"showt(this);\">-exec<\/span> <span id=\"c6\" title=\"This is the command executed on each file where {} is replaced by the actual filename ( eg. fgrep body $HOME\/Documents\/index.html \/dev\/null ).\" onclick=\"showt(this);\">fgrep body {} \/dev\/null<\/span> <span id=\"c7\" title=\"End of command.\" onclick=\"showt(this);\"> ;<\/span><\/li>\n<\/ul>\n<p>So today we see some actions to find and\/or locate files\/directories with this <a target=_blank href=\"\/Linux\/locate\/LocateFind_Linux.jpg\" title=\"Click picture\">tutorial<\/a>.<\/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='#d7067' onclick='var dv=document.getElementById(\"d7067\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Linux\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7067' 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='#d8074' onclick='var dv=document.getElementById(\"d8074\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=command-line\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d8074' 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='#d8368' onclick='var dv=document.getElementById(\"d8368\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=security\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d8368' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today, was going to show you comparisons of PHP[\/HTML] versus Javascript\/Ajax\/HTML versus Javascript\/HTML methodologies to have a password protected report only reported, securely (or not), to interested parties &#8230; ie. bits of talk regarding &#8220;security&#8221; &#8230; but today there is &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-wheres-wally-test-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,37],"tags":[69,234,274,452,576,652,677,707,740,744,932,997,1114,1319,1411],"class_list":["post-8368","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-ajax","tag-command-line","tag-crontab","tag-form","tag-html","tag-javascript","tag-korn-shell","tag-linux","tag-mailx","tag-mamp","tag-php","tag-programming","tag-security","tag-tutorial","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/8368"}],"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=8368"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/8368\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=8368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=8368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=8368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}