<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>olivetalks &#187; PHP</title>
	<atom:link href="http://www.olivetalks.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.olivetalks.com</link>
	<description>The Olive has arrived and it has things to say…</description>
	<lastBuildDate>Tue, 16 Nov 2010 19:25:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>php.ini, symlink and moodle: I&#8217;m calling it the php.ini fiasco</title>
		<link>http://www.olivetalks.com/2008/01/21/php_ini-fiasco-with-moodle/</link>
		<comments>http://www.olivetalks.com/2008/01/21/php_ini-fiasco-with-moodle/#comments</comments>
		<pubDate>Mon, 21 Jan 2008 22:09:22 +0000</pubDate>
		<dc:creator>LadyRostand</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[FileZilla]]></category>
		<category><![CDATA[Moodle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[symlink]]></category>

		<guid isPermaLink="false">http://www.olivetalks.com/2008/01/21/php_ini-fiasco-with-moodle/</guid>
		<description><![CDATA[Ok, fiasco is a bit harsh. It has not been a complete failure. Just somewhat of a headache&#8230;
In my post Register_Globals Off  and PHP4, I went through the steps I took to achieve setting register_globals = OFF in my server. I was quite excited with my success and everything seemed to work just fine. [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, fiasco is a bit harsh. It has not been a complete failure. Just somewhat of a headache&#8230;</p>
<p>In my post <a href="/2008/01/17/register_globals-off-and-php4/" rel="bookmark" title="Permanent Link: Register_Globals Off  and PHP4">Register_Globals Off  and PHP4</a>, I went through the steps I took to achieve setting register_globals = OFF in my server. I was quite excited with my success and everything seemed to work just fine. Obviously, 24 hours later, the problems started to surface.</p>
<p>Now, I&#8217;m still quite happy with the whole php.ini and symlink procedure, but the same way I wrote a post on the coolness of the process, I think it will be good to share the bad experiences, in case I can prevent or at least, warn, other people in the same situation.</p>
<p>So far, the most important &#8220;bad&#8221; consequence of symlinking the php.ini file in all the folders in the server has been its interaction with how Moodle handles the uploaded assignments of students.</p>
<p>When tutors went to grade their students uploades tasks, they found that most uploaded .odt, .doc, .ods, .xls, .pdf, &#8230; documents had been replaced by php.ini. And the original exercises seemed to have disappeared overnight.</p>
<p>Moodle uses the following folder system:<br />
http://domain-name/moodle-installation/file.php/7/moddata/assignment/19/6/exercise</p>
<p>where, in this example,</p>
<ul>
<li>7 is the course number</li>
<li>19 is the assignment number</li>
<li>6 would be the student&#8217;s number</li>
</ul>
<p>And what Moodle does is once a student has uploaded an exercise, it will display the most recent file in that folder. As you can see in the following image, although the task of the student was uploaded on the 27th of September 2007, it is showing the task as php.ini (which was really created on the date of my previous post, January 17th):</p>
<p style="text-align: center"><a href="/wp-content/uploads/2008/01/moodle1c.png" title="moodle-1"><img src="/wp-content/uploads/2008/01/moodle1tiny.png" alt="moodle-1" /></a></p>
<p>To see and correct the problem, you must access the folder:<br />
/moodle-installation/uploaddata/7/moddata/assignment/19/6/</p>
<p>As you can see in the next image (the images are linked to their full sizes so you can see them better):</p>
<p align="center"> <a href="/wp-content/uploads/2008/01/moodle2.png" title="moodle-2"><img src="/wp-content/uploads/2008/01/moodle2tiny.png" alt="moodle-2" /></a></p>
<p>in the folder for this student, for this particular assignment and course, besides the original file the student uploaded in September, there is the php.ini symlink (Filezilla identifies it as a folder).</p>
<p>As the php.ini symlink, saying that register_globals should be off, is only strictly needed in the folders where php scripts are executed from, it is not really necessary to have the symlink there. So you can &#8220;just&#8221; erase it. If you are using FileZilla, you might have the program ignore your request and complain that:</p>
<p>550 Can&#8217;t change directory to php.ini: Not a directory</p>
<p>Well, I knew that&#8230; Solution I have found: create a folder, move the php.ini symlink to that folder, and erase the folder with the php.ini inside. It seems to work. For completeness I will add that the FileZilla &#8220;Not a directory&#8221; complain, showed up both in a FileZilla run in Linux and in a Virtual Machine Windows XP Installation. It did not complain, however, in a FileZilla in a laptop running Windows XP.</p>
<p>Once the php.ini symlink is erased, Moodle will display the correct uploaded task again.</p>
<p align="center"><a href="/wp-content/uploads/2008/01/moodle3c.png" title="moodle-3"><img src="/wp-content/uploads/2008/01/moodle3tiny.png" alt="moodle-3" /></a></p>
<p>This process if you have loads of students/assignments, can be a bit of a pain. Obviously, a script could be written to erase the php.ini symlink from the assignment folders, or even better, the initial symlink script could be modified to exclude the Moodle folders where you don&#8217;t want the symlink created. Without either of these scripts, though</p>
<ol>
<li>it would be better to run symlink, before any students enroll in the courses</li>
<li>if you have a server with a Moodle installation and want to install a 2nd one&#8230; I would be weary of running symlink again without some solution&#8230;</li>
</ol>
<p>No, I do not have that solution, but if anybody does, I&#8217;m all ears. And if anybody finds him or herself in a similar situation, or has other problems with Moodle, do share your experiences with me! I might be able to help or learn from you  <img src='http://www.olivetalks.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<hr align="left" width="20%" /> <a href="/category/computers/feed" title="rss feed to post"><img src="/wp-content/uploads/2008/01/feed-icon-14x14.png" alt="rss feed to post" /></a> Subscribe to the Computers posts of olivetalks, if you found this article interesting, thank you!</p>
<h3>Related post(s)</h3><ul class="related_post"><li><a href="http://www.olivetalks.com/2008/10/30/inodes-28-weeks-later/" title="Inodes 28 weeks later&#8230;">Inodes 28 weeks later&#8230; (2)</a></li><li><a href="http://www.olivetalks.com/2008/03/09/inodes-attack-part2/" title="The return of the inodes &#8211; tell me your package and I&#8217;ll tell you your inodes">The return of the inodes &#8211; tell me your package and I&#8217;ll tell you your inodes (6)</a></li><li><a href="http://www.olivetalks.com/2008/03/04/hostgator-pros-cons/" title="Hostgator: pros and cons of their web hosting offer">Hostgator: pros and cons of their web hosting offer (17)</a></li><li><a href="http://www.olivetalks.com/2008/01/17/register_globals-off-and-php4/" title="Register_Globals Off  and PHP4">Register_Globals Off  and PHP4 (1)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.olivetalks.com/2008/01/21/php_ini-fiasco-with-moodle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Register_Globals Off  and PHP4</title>
		<link>http://www.olivetalks.com/2008/01/17/register_globals-off-and-php4/</link>
		<comments>http://www.olivetalks.com/2008/01/17/register_globals-off-and-php4/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 09:00:47 +0000</pubDate>
		<dc:creator>LadyRostand</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.olivetalks.com/2008/01/17/register_globals-off-and-php4/</guid>
		<description><![CDATA[I needed to set register_globals = OFF in my server yesterday and had a bit of a hard time finding out how to do it, as Hostgator (where this blog is hosted) does not have an easy way of changing it in the shared servers packages. I found tons of very helpful pages in blogs [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to set register_globals = OFF in my server yesterday and had a bit of a hard time finding out how to do it, as Hostgator (where this blog is hosted) does not have an easy way of changing it in the shared servers packages. I found tons of very helpful pages in blogs and forums all over the Web which helped me solve the problem. I feel it&#8217;s about time I give something back, besides taking this opportunity to thank all of you out there taking the time to help others.</p>
<p>So I learnt&#8230;</p>
<ol class="spaced">
<li>to set the register_globals off, one must place a &#8220;php.ini&#8221; file with the line register_globals = OFF in every folder of the server (thank you <a href="http://forum.joomla.org/index.php/topic,91837.msg465727.html" title="bergmann joomla forum">bergmann</a> at the <em>joomla forum</em>!)</li>
<li>but this php.ini cannot just contain the register_globals line. The Computer guys at the University of Washington explain it really well in <a href="http://www.washington.edu/computing/web/publishing/php-ini.html" title="Using a php.ini File">Using a php.ini File</a>, basically saying: if the directory that calls a PHP script contains a php.ini file, that is the one (and only) from where the PHP configuration settings will be read, so you must first obtain the Web server&#8217;s php.ini file and add your own particular settings.</li>
<li>now, I don&#8217;t know about other Hosting services, but you cannot access the php.ini file in Hostgator through ftp directly. <a href="http://www.amember.com/forum/showthread.php?p=23962" title="ronniead amember forum">ronniead</a> in a brilliant step by step post in an <em>aMember Professional</em> forum, explains how to use a script to both copy the original php.ini file of the Web server and add the extra user settings. This &#8220;<a href="http://tips-scripts.com/php_ini" title="php_ini script for PHP5.">Creating a custom php.ini file</a>&#8221; script from <em>B&amp;T&#8217;s Tips &amp; Scripts</em> is easy to download and use, following <a href="http://www.amember.com/forum/showthread.php?p=23962" title="ronniead amember forum">ronniead</a> instructions. Only one catch.. it did not work for me.</li>
<li>a bit more research and I found out that  the function which appears in the script from <em>B&amp;T&#8217;s Tips &amp; Scripts</em>: file_put_contents() works with PHP5 but not with PHP4 which is what I have. Some googling for &#8220;file_put_contents() for PHP4&#8243; brings up quite a few implementations of the PHP5 file_put_contents() function for PHP4. The one I settled for can be found in <a href="http://www.phpied.com/file_get_contents-for-php4/" title="file_put_contents for PHP4">Stoyan Stefanov</a>&#8217;s blog <a href="http://www.phpied.com/" title="phpied.com">phpied.com</a> (thanks Stoyan!)</li>
<li>So a bit of messing around with both the script and Stoyan&#8217;s implementation and I finally got the script to create a custom php.ini file for PHP4 working. And here comes the moment to give back to society.</li>
<li> You can either copy and paste the following code in a text editor, and then save as php_ini.php, or download the script from here: <a href="/wp-content/uploads/2008/03/php_ini_php4.txt" title="php4.txt">php_ini_PHP4.txt</a> (right-click, Save Link As&#8230; and as it&#8217;s in .txt format, once downloaded, change the ending to .php).</li>
</ol>
<p><code><br />
<span style="color: #0000bb; background-color: #fbf27a">&lt;?php</span><br />
// Put all the php.ini parameters you want to change below. One per line.<br />
// Follow the example format $parm[] = "parameter = value";<br />
<span style="color: #0000bb; font-style: italic">$parm</span>[] = <span style="color: #58c70d">"register_globals = Off"</span>;<br />
<span style="color: #0000bb; font-style: italic">$parm</span>[] = <span style="color: #58c70d">"session.use_trans_sid = 0 "</span>;</code><br />
<code><br />
// full unix path - location of the default php.ini file at your host<br />
// you can determine the location of the default file using phpinfo()<br />
<span style="color: #0000bb; font-style: italic">$defaultPath</span> = <span style="color: #58c70d">'/usr/local/lib/php.ini'</span>;</code><br />
<code><br />
// full unix path - location where you want your custom php.ini file<br />
// if you don't know the full unix path, uncomment the next line and run the script<br />
// echo getcwd() . "\n";<br />
// you will see the full path (and probably an error message)<br />
<span style="color: #0000bb; font-style: italic">$customPath</span> = <span style="color: #58c70d">"/home/user/public_html/php.ini"</span>;</code><br />
<code><br />
// nothing should change below this line.<br />
<span style="color: #924eb1; font-style: italic">if</span> (file_exists(<span style="color: #0000bb; font-style: italic">$defaultPath</span>)) {<br />
<span style="color: #0000bb; font-style: italic">$contents</span> = file_get_contents(<span style="color: #0000bb; font-style: italic">$defaultPath</span>);<br />
<span style="color: #0000bb; font-style: italic">$contents</span> .= <span style="color: #58c70d">"\n\n; USER MODIFIED PARAMETERS FOLLOW\n\n"</span>;<br />
<span style="color: #924eb1; font-style: italic">foreach</span> (<span style="color: #0000bb; font-style: italic">$parm</span> <span style="color: #924eb1; font-style: italic">as</span> <span style="color: #0000bb; font-style: italic">$value</span>) <span style="color: #0000bb; font-style: italic">$contents</span> .= <span style="color: #0000bb; font-style: italic">$value</span> . <span style="color: #58c70d">" \n"</span>;</code><br />
<code><br />
// code added for the script to work with PHP4<br />
<span style="color: #924eb1; font-style: italic">if</span> (!function_exists(<span style="color: #58c70d">'file_put_contents'</span>)) {<br />
<span style="color: #924eb1; font-style: italic">function</span> file_put_contents(<span style="color: #0000bb; font-style: italic">$customPath</span>,<span style="color: #0000bb; font-style: italic">$contents</span>) {<br />
<span style="color: #0000bb; font-style: italic">$f</span> = @fopen(<span style="color: #0000bb; font-style: italic">$customPath</span>, <span style="color: #58c70d; font-style: italic">'w'</span>);<br />
<span style="color: #924eb1; font-style: italic">if</span> (!<span style="color: #0000bb; font-style: italic">$f</span>) {<br />
<span style="color: #924eb1; font-style: italic">return false</span>;<br />
} <span style="color: #924eb1; font-style: italic">else</span> {<br />
<span style="color: #0000bb; font-style: italic">$bytes</span> = fwrite(<span style="color: #0000bb; font-style: italic">$f</span>, <span style="color: #0000bb; font-style: italic">$contents</span>);<br />
fclose(<span style="color: #0000bb; font-style: italic">$f</span>);<br />
<span style="color: #924eb1; font-style: italic">return</span> <span style="color: #0000bb; font-style: italic">$bytes</span>;<br />
}<br />
}<br />
}<br />
// end of added code for script to work with PHP4</code><br />
<code><br />
<span style="color: #924eb1; font-style: italic">if</span> (file_put_contents(<span style="color: #0000bb; font-style: italic">$customPath</span>,<span style="color: #0000bb; font-style: italic">$contents</span>)) {<br />
<span style="color: #924eb1; font-style: italic">if</span> (chmod(<span style="color: #0000bb; font-style: italic">$customPath</span>,0600)) <span style="color: #0000bb; font-style: italic">$message</span> = <span style="color: #58c70d; font-style: italic">"The php.ini file has been modified and copied"</span>;<br />
<span style="color: #924eb1; font-style: italic">else</span> <span style="color: #0000bb; font-style: italic">$message</span> = <span style="color: #58c70d">"Processing error - php.ini chmod failed"</span>;<br />
} <span style="color: #924eb1; font-style: italic">else</span> {<br />
<span style="color: #0000bb; font-style: italic">$message</span> = <span style="color: #58c70d">"Processing error - php.ini write failed"</span>;<br />
}<br />
} <span style="color: #924eb1; font-style: italic">else</span> {<br />
<span style="color: #0000bb; font-style: italic">$message</span> = <span style="color: #58c70d">"Processing error - php.ini file not found"</span>;</code><br />
<code><br />
}<br />
<span style="color: #924eb1; font-style: italic">echo</span> <span style="color: #0000bb; font-style: italic">$message</span>;<br />
<span style="color: #0000bb; background-color: #fbf27a">?&gt;</span><br />
</code></p>
<p>So there it is, the script to create the custom php.ini file for PHP4. Let me know how it goes!</p>
<hr align="left" width="20%" /> <a href="/category/computers/feed" title="rss feed to post"><img src="/wp-content/uploads/2008/01/feed-icon-14x14.png" alt="rss feed to post" /></a> Subscribe to the Computers posts of olivetalks, if you found this article interesting, thank you!</p>
<h3>Related post(s)</h3><ul class="related_post"><li><a href="http://www.olivetalks.com/2008/10/30/inodes-28-weeks-later/" title="Inodes 28 weeks later&#8230;">Inodes 28 weeks later&#8230; (2)</a></li><li><a href="http://www.olivetalks.com/2008/03/09/inodes-attack-part2/" title="The return of the inodes &#8211; tell me your package and I&#8217;ll tell you your inodes">The return of the inodes &#8211; tell me your package and I&#8217;ll tell you your inodes (6)</a></li><li><a href="http://www.olivetalks.com/2008/03/05/inodes-attack-part1/" title="The attack of the inodes &#8211; how to find out your number">The attack of the inodes &#8211; how to find out your number (11)</a></li><li><a href="http://www.olivetalks.com/2008/03/04/hostgator-pros-cons/" title="Hostgator: pros and cons of their web hosting offer">Hostgator: pros and cons of their web hosting offer (17)</a></li><li><a href="http://www.olivetalks.com/2008/01/21/php_ini-fiasco-with-moodle/" title="php.ini, symlink and moodle: I&#8217;m calling it the php.ini fiasco">php.ini, symlink and moodle: I&#8217;m calling it the php.ini fiasco (0)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.olivetalks.com/2008/01/17/register_globals-off-and-php4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

