{"id":57500,"date":"2022-11-17T03:01:47","date_gmt":"2022-11-16T17:01:47","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=57500"},"modified":"2022-11-20T17:30:41","modified_gmt":"2022-11-20T07:30:41","slug":"apache-php-code-control-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/apache-php-code-control-tutorial\/","title":{"rendered":"Apache PHP Code Control Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/Games\/Noughtsandcrosses\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Apache PHP Code Control Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Games\/Noughtsandcrosses\/tic_tac_toe_notification.jpg\" title=\"Apache PHP Code Control Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Apache PHP Code Control Tutorial<\/p><\/div>\n<p>It might be tempting to ask, after the event, with web application code on an Apache web server, can controlling code be added to an existing web application codeset, that does not rely on changes to any existent code?  The answer is yes, with a lot of provisos &#8230;<\/p>\n<ul>\n<li>it&#8217;s not a great idea, as much to do with causing confusion as to do with security looseness &#8230; but, nonetheless, depending on other php.ini configurations you might be able to add &#8230;<\/li>\n<li>into Apache domain&#8217;s <a target=_blank title='Apache PHP php.ini configuration file' href='https:\/\/www.php.net\/manual\/en\/configuration.file.php'>php.ini<\/a> configuration file &#8230;<br \/>\n<code><br \/>\n; Automatically add files before or after any PHP document.<br \/>\nauto_prepend_file = somestartingphp.php<br \/>\nauto_append_file = someendingphp.php<br \/>\n<\/code><br \/>\n &#8230; as we intimated in <a title='Apache\/PHP\/MySql Linux Language Considerations Primer Tutorial' href='#a\/php\/msllcpt'>Apache\/PHP\/MySql Linux Language Considerations Primer Tutorial<\/a> &#8230; or &#8230;<\/li>\n<li>within a folder of Apache web server directory structure via an Apache <a target=_blank title='Apache .htaccess information' href='https:\/\/httpd.apache.org\/docs\/2.4\/howto\/htaccess.html'>.htaccess<\/a> file mention, such as &#8230;<br \/>\n<code><br \/>\nphp_value auto_prepend_file ..\/..\/ncmailxitin.php<br \/>\nphp_value auto_append_file ..\/..\/ncmailxitout.php<br \/>\n<\/code><br \/>\n &#8230; the exact contents of our MAMP Apache .htaccess for HTTP:\/\/localhost:8888\/Games\/Noughtsandcrosses\/ in explanation below<\/li>\n<\/ul>\n<p>We were kind of sad and relieved at the same time seeing that to apply this .htaccess approach of allowing for introductory Notification welcome messages up at the RJM Programming domain&#8217;s <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/Games\/Noughtsandcrosses\/\" title=\"Tic tac toe\"><i>Noughts and Crosses<\/i><\/a> web application we tried it on, but it did not work, whereas trying to apply it to our Apache <a target=_blank title='MAMP' href='http:\/\/www.mamp.info'>MAMP<\/a> <font size=1>(local web server)<\/font> environment via &#8230;<\/p>\n<ul>\n<li>downloaded existing code to MAMP place in Games\/Noughtsandcrosses off the MAMP Document Root folder &#8230;<\/li>\n<li>tweaked <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=https:\/\/www.rjmprogramming.com.au\/Games\/Noughtsandcrosses\/tictactoe.js-------GETME\" title=\"tictactoe.js\">the changed<\/a> <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/Games\/Noughtsandcrosses\/tictactoe.js-------GETME\" title=\"tictactoe.js\">tictactoe.js<\/a> &#8230; in a way that suited allowing new introductory Notifications welcoming players in both MAMP and RJM Programming domain <i>brands<\/i> of Apache web servers, but in different ways &#8230; please note that this change to existent code would not have been needed had the RJM Programming domain accepted the .htaccess methodologies, and we were not wanting the same <i>Noughts and Crosses<\/i> codeset suiting both Apache environments &#8230;<\/li>\n<li>renamed the Games\/Noughtsandcrosses index.html (default web application filename) to index.php &#8230; to allow for an Apache .htaccess methodology to possibly work <font size=1>(but only does, for us, at MAMP)<\/font> &#8230; it&#8217;s only noticed when PHP code is involved <font size=1>(even if there are no starting <i>&lt;?php <\/i> and ending <i> ?&gt;<\/i> delimitations in the code, as in our, what was, index.html case)<\/font> &#8230;<\/li>\n<li>created a 644 permissions .htaccess in Games\/Noughtsandcrosses off the MAMP Document Root folder &#8230;<br \/>\n<code><br \/>\nphp_value auto_prepend_file ..\/..\/ncmailxitin.php<br \/>\nphp_value auto_append_file ..\/..\/ncmailxitout.php<br \/>\n<\/code>\n<\/li>\n<li>created in MAMP Document Root folder <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/ncmailxitin.php_GETME\" title=\"ncmailxitin.php\">ncmailxitin.php<\/a> &#8230;<\/li>\n<li>created in MAMP Document Root folder <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/ncmailxitout.php_GETME\" title=\"ncmailxitout.php\">ncmailxitout.php<\/a><\/li>\n<\/ul>\n<p> &#8230; did!<\/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\/apachephpmysql-linux-language-considerations-primer-tutorial\/'>Apache\/PHP\/MySql Linux Language Considerations Primer Tutorial<\/a>.<\/p-->\n<hr>\n<p id='a\/php\/msllcpt'>Previous relevant <a target=_blank title='Apache\/PHP\/MySql Linux Language Considerations Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/apache\/php\/mysql-linux-language-considerations-primer-tutorial\/'>Apache\/PHP\/MySql Linux Language Considerations Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/mamp_language.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Apache\/PHP\/MySql Linux Language Considerations Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/mamp_language.jpg\" title=\"Apache\/PHP\/MySql Linux Language Considerations Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Apache\/PHP\/MySql Linux Language Considerations Primer Tutorial<\/p><\/div>\n<p>The recent <a target=_blank title='CSS Style Javascript DOM Override Onload Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/css-style-javascript-dom-override-onload-primer-tutorial\/'>CSS Style Javascript DOM Override Onload Primer Tutorial<\/a> &#8220;proof of concept&#8221; web application ended up with the name &#8230;<\/p>\n<p><code><br \/>\n<a target=_blank title='are_you_happy_with_my_or_do_you_think_my_derriere_needs_work.html' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/are_you_happy_with_my_or_do_you_think_my_derriere_needs_work.html'>are_you_happy_with_my_or_do_you_think_my_derriere_needs_work.html<\/a><br \/>\n<\/code><\/p>\n<p> &#8230; but along the way we wanted to call it &#8230;<\/p>\n<p><code><br \/>\nare_you_happy_with_my_or_do_you_think_my_derri\u00e8re_needs_work.html<br \/>\n<\/code><\/p>\n<p> &#8230; but this didn&#8217;t work as an RJM Programming website filename.  Rather than make it work, we compromised, and called it (the final)  are_you_happy_with_my_or_do_you_think_my_derriere_needs_work.html it ended up as.  But this didn&#8217;t stop us wondering about all this language and the relationship of these language characters and where and how you can or can&#8217;t use those characters outside those usual US-keyboard type characters.<\/p>\n<p>And that brings us to the great <a target=_blank title='MAMP local Apache\/PHP\/MySQL' href='http:\/\/mamp.info'>MAMP<\/a> local Apache\/PHP\/MySql web server product, as a place to experiment, comforted in the knowledge that the Mac OS X Terminal application &#8230;<\/p>\n<p><code><br \/>\nls -li<br \/>\n<\/code><\/p>\n<p> &#8230; and knowledge of inodes (all the way to their &#8220;extreme case Linux system file removal talents) you can read about at <a target=_blank title='Linux Inode File Removal Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-inode-file-removal-tutorial\/'>Linux Inode File Removal Tutorial<\/a> would probably protect me from home grown stupidities.<\/p>\n<p>So what followed for me was a quick look at MAMP&#8217;s relevant php.ini file and its httpd.conf configuration files to see that the web server default &#8220;goto look for&#8221; file list for the web server directory can be altered by a change of &#8230;<\/p>\n<p><code><br \/>\nDirectoryIndex index.html index.php<br \/>\n<\/code><\/p>\n<p> &#8230; to something else in httpd.conf Apache configuration file.  But nothing to easily reinvent the US-keyboard feeling file extensions .htm and .html and .php that was apparent to me.  And noting to change that &#8230;<\/p>\n<p><code><br \/>\n[protocol]:\/\/localhost:[localHostPortNumber]\/<br \/>\n<\/code><\/p>\n<p> &#8230; US-keyboard feeling prefix to a URL, such as our http:\/\/localhost:8888\/ prefix to a MAMP local Apache\/PHP\/MySql URL we created a Simplified Chinese character set &#8220;Hello World&#8221; folder scenario (and thank <a target=_blank title='Google Translate' href='http:\/\/translate.google.com'>Google Translate<\/a> for translation help today) &#8230;<\/p>\n<p><code><font color=black>ht<\/font>tp:\/\/localhost:8888\/\u4f60\u597d\/\u4e16\u754c\/<\/code><\/p>\n<p>index.html as per &#8230;<\/p>\n<p><code><br \/>\n&lt;!doctype html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;RJM\u7f16\u7a0b\u7740\u9646\u9875&lt;\/title&gt;<br \/>\n&lt;meta charset=\"UTF-8\"&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;h1&gt;\u6b22\u8fce\u6765\u5230-RJM\u7f16\u7a0b\u7f51\u7ad9&lt;\/h1&gt;&lt;br&gt;<br \/>\n&lt;a target=_blank title='RJM\u7f16\u7a0b\u7740\u9646\u9875' href='https:\/\/translate.google.com\/translate?sl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=%2F%2Fwww.rjmprogramming.com.au%2Findex.html&tl=zh-CN'&gt;RJM\u7f16\u7a0b\u7740\u9646\u9875&lt;\/a&gt;<br \/>\n&lt;\/body&gt;&lt;\/html&gt;<br \/>\n<\/code><\/p>\n<p>Within the php.ini configuration file we found interesting, in particular &#8230;<\/p>\n<p><code><br \/>\n; Automatically add files before or after any PHP document.<br \/>\nauto_prepend_file =<br \/>\nauto_append_file =<br \/>\n<b><\/b><br \/>\n; PHP's built-in default is text\/html<br \/>\ndefault_mimetype = \"text\/html\"<br \/>\n<b><\/b><br \/>\n; Whether to allow the treatment of URLs (like http:\/\/ or ftp:\/\/) as files.<br \/>\nallow_url_fopen = On<br \/>\n<\/code><\/p>\n<p> &#8230; the last of which, if set to <i>Off<\/i> could set up for the scenario of setting up a web server full of index.html and index.php code in web server folders that could include non US-keyboard characters, and so you could have within the code of &#8230;<\/p>\n<p><code><font color=black>ht<\/font>tp:\/\/localhost:8888\/\u4f60\u597d\/<\/code><\/p>\n<p> index.html a relative URL such as &#8230;<\/p>\n<p><code>&lt;a target=_blank title='\u4f60\u597d \u4e16\u754c' href='\u4e16\u754c'&gt;\u4f60\u597d \u4e16\u754c&lt;\/a&gt;<\/code><\/p>\n<p> &#8230; taking you off to today&#8217;s (URL) starting place.<\/p>\n<p>Am sure you can feel yourself, there is so much more to explore in this topic area, and we&#8217;ll be returning soon to this neck of the woods soon, we hope.  In the meantime, take a look at our <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/mamp_language.jpg\" title='Click picture'>tutorial picture<\/a> for a bit of what we did on MAMP with some of these concepts not changing any configuration files at all.<\/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='#d30401' onclick='var dv=document.getElementById(\"d30401\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/mamp\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d30401' 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='#d57500' onclick='var dv=document.getElementById(\"d57500\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/apache\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d57500' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>It might be tempting to ask, after the event, with web application code on an Apache web server, can controlling code be added to an existing web application codeset, that does not rely on changes to any existent code? The &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/apache-php-code-control-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":[42,85,2236,4149,4148,218,4150,249,1750,355,450,476,714,744,847,932,2119,4151,997,1114,1275,1319,1411,1418,1421],"class_list":["post-57500","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-htaccess","tag-apache","tag-append","tag-auto_append_file","tag-auto_prepend_file","tag-code","tag-codeset","tag-configuration","tag-document-root","tag-domain","tag-folder","tag-game","tag-local-web-server","tag-mamp","tag-noughts-and-crosses","tag-php","tag-php-ini","tag-prepend","tag-programming","tag-security","tag-tic-tac-toe","tag-tutorial","tag-web-server","tag-webpage","tag-website"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57500"}],"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=57500"}],"version-history":[{"count":15,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57500\/revisions"}],"predecessor-version":[{"id":57574,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57500\/revisions\/57574"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=57500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=57500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=57500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}