<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Tutorial: PHP Random Image</title>
	<atom:link href="http://www.zyaga.com/2009/11/09/tutorial-php-random-image/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zyaga.com/2009/11/09/tutorial-php-random-image/</link>
	<description>Live Learning with Zyaga</description>
	<lastBuildDate>Wed, 17 Feb 2010 02:09:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Zyaga</title>
		<link>http://www.zyaga.com/2009/11/09/tutorial-php-random-image/comment-page-1/#comment-1037</link>
		<dc:creator>Zyaga</dc:creator>
		<pubDate>Thu, 19 Nov 2009 19:10:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.zyaga.com/?p=1319#comment-1037</guid>
		<description>Yeah, I know it will miss those items. You probably didn&#039;t read the text again of my article, since you&#039;ve went over it before, but that&#039;s why I stated that I know I personally only use .jpg, .gif, and .png

That way I know that any file other than those is incorrect, even if it was an image it wouldn&#039;t be an image &quot;I&quot; would want to display. :P

Going through your blog right now. Got a lot of interesting articles. Been needing to start up a Development blogroll anyway, so I went ahead and started it by adding you. ;)</description>
		<content:encoded><![CDATA[<p>Yeah, I know it will miss those items. You probably didn&#8217;t read the text again of my article, since you&#8217;ve went over it before, but that&#8217;s why I stated that I know I personally only use .jpg, .gif, and .png</p>
<p>That way I know that any file other than those is incorrect, even if it was an image it wouldn&#8217;t be an image &#8220;I&#8221; would want to display. <img src='http://www.zyaga.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Going through your blog right now. Got a lot of interesting articles. Been needing to start up a Development blogroll anyway, so I went ahead and started it by adding you. <img src='http://www.zyaga.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Haugeland</title>
		<link>http://www.zyaga.com/2009/11/09/tutorial-php-random-image/comment-page-1/#comment-1034</link>
		<dc:creator>John Haugeland</dc:creator>
		<pubDate>Thu, 19 Nov 2009 18:03:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.zyaga.com/?p=1319#comment-1034</guid>
		<description>Actually as a generalization thing that should probably be two separate functions.

&lt;?php

    function random_from($Array) { 

        assert(is_array($Array));
        assert(length($Array) &gt; 0);

        return $Array[rand(0,length($Array))];

    }

?&gt;

Then implementing in terms of that is clear and natural.

random_from is present in my library, FWIW, in a somewhat stronger form.  http://scutil.com/ .</description>
		<content:encoded><![CDATA[<p>Actually as a generalization thing that should probably be two separate functions.</p>
<p>&lt;?php</p>
<p>    function random_from($Array) { </p>
<p>        assert(is_array($Array));<br />
        assert(length($Array) &gt; 0);</p>
<p>        return $Array[rand(0,length($Array))];</p>
<p>    }</p>
<p>?&gt;</p>
<p>Then implementing in terms of that is clear and natural.</p>
<p>random_from is present in my library, FWIW, in a somewhat stronger form.  <a href="http://scutil.com/" rel="nofollow">http://scutil.com/</a> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Haugeland</title>
		<link>http://www.zyaga.com/2009/11/09/tutorial-php-random-image/comment-page-1/#comment-1033</link>
		<dc:creator>John Haugeland</dc:creator>
		<pubDate>Thu, 19 Nov 2009 17:58:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.zyaga.com/?p=1319#comment-1033</guid>
		<description>Er, sorry about the rand() error.  Feel free to edit mine to make it correct, if you&#039;d like.

As far as what I&#039;d like you to add to the article?  More articles.  This is sort of a one-off topic.  Keep in touch with me from http://fullof.bs/ and I&#039;ll post other commentary if you want.

It might be nice if the extensions were a default value to a function parameter, so that the user could specify other extension types if they want to (like .bmp, .xpm, .svg, blah blah).  Also, that default list of yours will miss things called .jpeg, upper case extensions on unix, et cetera.</description>
		<content:encoded><![CDATA[<p>Er, sorry about the rand() error.  Feel free to edit mine to make it correct, if you&#8217;d like.</p>
<p>As far as what I&#8217;d like you to add to the article?  More articles.  This is sort of a one-off topic.  Keep in touch with me from <a href="http://fullof.bs/" rel="nofollow">http://fullof.bs/</a> and I&#8217;ll post other commentary if you want.</p>
<p>It might be nice if the extensions were a default value to a function parameter, so that the user could specify other extension types if they want to (like .bmp, .xpm, .svg, blah blah).  Also, that default list of yours will miss things called .jpeg, upper case extensions on unix, et cetera.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zyaga</title>
		<link>http://www.zyaga.com/2009/11/09/tutorial-php-random-image/comment-page-1/#comment-1032</link>
		<dc:creator>Zyaga</dc:creator>
		<pubDate>Thu, 19 Nov 2009 15:19:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.zyaga.com/?p=1319#comment-1032</guid>
		<description>Some good points, thanks for the idea to just use glob, soon the article will be adjusted appropriately.

I personally didn&#039;t think of writing a check as far as the image. Considering, it&#039;s server side and input is not being generated by anything other than a programmer calling it himself, although it could be used like that, though my example didn&#039;t.

However, I agree it is always good to double check things.

Also, one note: 
return $imgs[rand(length($imgs))]; 

should actually be: 

return $imgs[rand(0, count($imgs) - 1)];

Count instead of length and rand takes two arguments.

Very minor changes, but thought I&#039;d just point them out so that if anyone went to copy and paste it or something, they&#039;d realize it.

I&#039;ll update this, as it was actually something I wrote a long time ago but hadn&#039;t ever put online. I&#039;ll add an extension check as well to your glob, etc.

Glad to see you took the time to communicate this to me though along with letting me know on Twitter! ^_^

*Edit* Anything you&#039;d like to add to the article? I&#039;ve changed it to result in the ideas you&#039;ve said. You mentioned about checking to see if it&#039;s the appropriate directory. Not sure what you meant by that, but if you to check that they are in a certain folder to begin with, such as maybe under a specific site folder, then I think I&#039;ll leave that part to be defined by the user. If you meant something else, feel free to mention it. :)</description>
		<content:encoded><![CDATA[<p>Some good points, thanks for the idea to just use glob, soon the article will be adjusted appropriately.</p>
<p>I personally didn&#8217;t think of writing a check as far as the image. Considering, it&#8217;s server side and input is not being generated by anything other than a programmer calling it himself, although it could be used like that, though my example didn&#8217;t.</p>
<p>However, I agree it is always good to double check things.</p>
<p>Also, one note:<br />
return $imgs[rand(length($imgs))]; </p>
<p>should actually be: </p>
<p>return $imgs[rand(0, count($imgs) - 1)];</p>
<p>Count instead of length and rand takes two arguments.</p>
<p>Very minor changes, but thought I&#8217;d just point them out so that if anyone went to copy and paste it or something, they&#8217;d realize it.</p>
<p>I&#8217;ll update this, as it was actually something I wrote a long time ago but hadn&#8217;t ever put online. I&#8217;ll add an extension check as well to your glob, etc.</p>
<p>Glad to see you took the time to communicate this to me though along with letting me know on Twitter! ^_^</p>
<p>*Edit* Anything you&#8217;d like to add to the article? I&#8217;ve changed it to result in the ideas you&#8217;ve said. You mentioned about checking to see if it&#8217;s the appropriate directory. Not sure what you meant by that, but if you to check that they are in a certain folder to begin with, such as maybe under a specific site folder, then I think I&#8217;ll leave that part to be defined by the user. If you meant something else, feel free to mention it. <img src='http://www.zyaga.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Haugeland</title>
		<link>http://www.zyaga.com/2009/11/09/tutorial-php-random-image/comment-page-1/#comment-1029</link>
		<dc:creator>John Haugeland</dc:creator>
		<pubDate>Thu, 19 Nov 2009 14:13:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.zyaga.com/?p=1319#comment-1029</guid>
		<description>Unfortunately the last copy of this post suffered code removal by the blog.

------------

Sorry, but there’s a much easier way.

&lt;?php

    function randomImage($fromDir) {
        $imgs = glob($fromDir);
        return $imgs[rand(length($imgs))];
    }

?&gt;

For reference, this style of function is actually a potential security risk: it doesn’t check whether the target directory is a legitimate target, and it doesn’t check that what it’s loading is a legitimate image.

A better approach involves, at the very least, a second parameter to filter out tolerated extensions. Such a thing is, luckily, trivially straightforward with glob.</description>
		<content:encoded><![CDATA[<p>Unfortunately the last copy of this post suffered code removal by the blog.</p>
<p>&#8212;&#8212;&#8212;&#8212;</p>
<p>Sorry, but there’s a much easier way.</p>
<p>&lt;?php</p>
<p>    function randomImage($fromDir) {<br />
        $imgs = glob($fromDir);<br />
        return $imgs[rand(length($imgs))];<br />
    }</p>
<p>?&gt;</p>
<p>For reference, this style of function is actually a potential security risk: it doesn’t check whether the target directory is a legitimate target, and it doesn’t check that what it’s loading is a legitimate image.</p>
<p>A better approach involves, at the very least, a second parameter to filter out tolerated extensions. Such a thing is, luckily, trivially straightforward with glob.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
