<?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>Joey Rivera &#187; header()</title>
	<atom:link href="http://www.joeyrivera.com/tag/header/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joeyrivera.com</link>
	<description>Blogging about PHP, Actionscript, MySQL, and other interests.</description>
	<lastBuildDate>Wed, 04 Aug 2010 14:52:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Random image from folder &#8211; rotating banner in php</title>
		<link>http://www.joeyrivera.com/2008/random-image-from-folder-rotating-banner-in-php/</link>
		<comments>http://www.joeyrivera.com/2008/random-image-from-folder-rotating-banner-in-php/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 15:35:16 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[header()]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[opendir]]></category>
		<category><![CDATA[preg_match]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[readdir]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=263</guid>
		<description><![CDATA[So the other day someone was looking for a quick php script that would load a random image from a folder (rotating banner script) and display it on their website. There are already a ton of scripts out there that do this but of course, this was an excuse to build something for fun. So, [...]]]></description>
			<content:encoded><![CDATA[<p>So the other day someone was looking for a quick php script that would load a random image from a folder (rotating banner script) and display it on their website. There are already a ton of scripts out there that do this but of course, this was an excuse to build something for fun. So, I decided to create a script that would do just this but with the least amount of code lines still keeping it efficient (again, just for fun). This is what I came up with:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="re0">$files</span> = @<a href="http://www.php.net/opendir"><span class="kw3">opendir</span></a><span class="br0">&#40;</span><span class="re0">$dir</span>=<a href="http://www.php.net/trim"><span class="kw3">trim</span></a><span class="br0">&#40;</span><span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;dir&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&#8216;Not Valid&#8217;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$file</span> = <a href="http://www.php.net/readdir"><span class="kw3">readdir</span></a><span class="br0">&#40;</span><span class="re0">$files</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <a href="http://www.php.net/preg_match"><span class="kw3">preg_match</span></a><span class="br0">&#40;</span><span class="st0">&#8216;/(.png)|(.gif)|(.jpg)/i&#8217;</span>,<span class="re0">$file</span><span class="br0">&#41;</span> ?<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$images</span><span class="br0">&#91;</span><span class="br0">&#93;</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$file</span>,<a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$file</span>,<a href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">&#40;</span><span class="re0">$file</span><span class="br0">&#41;</span><span class="nu0">-3</span><span class="br0">&#41;</span><span class="br0">&#41;</span> : <span class="kw2">null</span>;<br />
<a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$images</span><span class="br0">&#41;</span> ? <a href="http://www.php.net/header"><span class="kw3">header</span></a><span class="br0">&#40;</span><span class="st0">&#8216;Content-type: image/&#8217;</span>.<span class="re0">$images</span><span class="br0">&#91;</span><span class="re0">$id</span>=<a href="http://www.php.net/rand"><span class="kw3">rand</span></a><span class="br0">&#40;</span><span class="nu0">0</span>,<a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$images</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#41;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span> :<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&#8216;Not Valid&#8217;</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a> <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="re0">$dir</span>.<span class="br0">&#40;</span><a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$dir</span>,<a href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">&#40;</span><span class="re0">$dir</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#41;</span>!=<span class="st0">&#8216;/&#8217;</span>?<span class="st0">&#8216;/&#8217;</span>:<span class="kw2">null</span><span class="br0">&#41;</span>.<span class="re0">$images</span><span class="br0">&#91;</span><span class="re0">$id</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p><span id="more-263"></span></p>
<p>So, in 4 lines I was able to accomplish the task. The way this code works, you pass the script a dir where you want the images to be loaded from. The page will then read the folder and create an array of all the pngs, gifs, and jpgs in that folder. Finally, it&#8217;ll randomly pick one, send the header for the proper file type, and spit out the image.</p>
<p>Here&#8217;s the example link (every time you reload this page you should see a different image):<br />
<a href="http://www.joeyrivera.com/projects/random_image/rand_image.php?dir=../../uploader/sample/">http://www.joeyrivera.com/projects/random_image/rand_image.php?dir=../../uploader/sample/</a></p>
<p>The code for this to work in your page:</p>
<div class="dean_ch" style="white-space: wrap;">&lt;img src=<span class="st0">&quot;random_image.php?dir=/path/to/image/folder/&quot;</span> /&gt;</div>
<p style="text-align:center"><img src="http://www.joeyrivera.com/projects/random_image/rand_image.php?dir=../../uploader/sample/" alt="" width="100" height="100" /></p>
<p>Pros: Flexible since you can just pass it any dir you want without having to change the code</p>
<p>Cons: You can pass it the dir you want so someone could easily try passing it different dirs for images you might not want people to see.</p>
<p>I have added some security to this. If a folder doesn&#8217;t exists or a folder that does exist but doesn&#8217;t have any images is passed, the page will return a &#8216;Not Valid&#8217; message. Thoughts and/or comments are welcome. If you have an even better way of doing this do feel free to post. Hope this is useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2008/random-image-from-folder-rotating-banner-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting list of members from an event in meetup.com with PHP</title>
		<link>http://www.joeyrivera.com/2008/getting-list-of-members-from-an-event-in-meetupcom-with-php/</link>
		<comments>http://www.joeyrivera.com/2008/getting-list-of-members-from-an-event-in-meetupcom-with-php/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 21:28:20 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array_unique()]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[header()]]></category>
		<category><![CDATA[meetup]]></category>
		<category><![CDATA[meetup.com]]></category>
		<category><![CDATA[member list]]></category>
		<category><![CDATA[ob_flush()]]></category>
		<category><![CDATA[ob_start()]]></category>
		<category><![CDATA[preg_match_all()]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=242</guid>
		<description><![CDATA[So, last week I attended our monthly Atlanta PHP meet and had a good time. At the end of the session some prizes were awarded &#8220;randomly&#8221;. Why &#8220;randomly&#8221;? Because a member of the group wrote down two names on a piece of paper and started asking the other members for a number. The two to [...]]]></description>
			<content:encoded><![CDATA[<p>So, last week I attended our monthly <a title="atlanta php website" href="http://www.atlantaphp.org/" target="_blank">Atlanta PHP</a> meet and had a good time. At the end of the session some prizes were awarded &#8220;randomly&#8221;. Why &#8220;randomly&#8221;? Because a member of the group wrote down two names on a piece of paper and started asking the other members for a number. The two to get the numbers correct won an award. Now, this was a quick last minute thing for fun, so I am definitely over engineering this &#8211; but hey, that&#8217;s what makes programming fun!</p>
<p>The problems were:</p>
<ul>
<li>(and I apologize for my honesty in case any member that attended the event reads this) I could see the persons hand movement while writing down the numbers so I already knew one of the numbers before starting. </li>
<li>The paper was lifted at some point before he started calling out for numbers and I could see the second number written on the paper.</li>
<li>It&#8217;s not truly random</li>
</ul>
<p><span id="more-242"></span>After the event I went home inspired to create something. I wanted to create something that would be fun (don&#8217;t we all) and something that might be used. If I create something knowing it won&#8217;t get any use, I&#8217;ll lose interest fast and not finish. I started thinking about the event and the part that could be improved was the awarding of prizes so I decided to create something that would be more fair, truly random, and automated.</p>
<p>We use <a title="meetup.com website" href="http://www.meetup.com" target="_blank">meetup.com</a> to schedule events and RSVP for them. Our <a title="atlanta php meetup group" href="http://www.meetup.com/atlantaphp/" target="_blank">Atlanta PHP</a> group at meetup.com has a <a title="atlanta php calendar page" href="http://www.meetup.com/atlantaphp/calendar/" target="_blank">calendar</a> and I assume everyone else who uses their services has a calendar as well. Events are found in the calendar page with a link to the actual event page. In the <a title="example of atlanta php event" href="http://www.meetup.com/atlantaphp/calendar/9110295/" target="_blank">event page</a> (example of event for atlanta php), you can see the members who attended the event. Here is my assumption because I haven&#8217;t actually tested my theory yet. I assume that once the event starts, the list of RSVP and none attending members goes away and only the list of attending members stays.</p>
<p>Assuming my theory is correct, I can create a php page that will take in an event url as a parameter, gets the html for that page, searches for all members in that page, and spits out the list. Then I can pass another parameter for the number of prizes that need to be awarded from the list of members. The end result would be a list of all members who attended with another list of the random winners. This would solve the problems mentioned above and would be easy to use. Pass in an event url from the calendar page at the end of the meeting with a number of prizes and there you have your winners.</p>
<p>So after a few hours the page is done and here it is with a couple different uses:</p>
<p><a href="http://www.joeyrivera.com/atlantaphp/prize.php">http://www.joeyrivera.com/atlantaphp/prize.php</a></p>
<p><a href="http://www.joeyrivera.com/atlantaphp/prize.php?event=http://www.meetup.com/atlantaphp/calendar/9110295/">http://www.joeyrivera.com/atlantaphp/prize.php?event=http://www.meetup.com/atlantaphp/calendar/9110295/</a><br />
<a href="http://www.joeyrivera.com/atlantaphp/prize.php?event=http://www.meetup.com/atlantaphp/calendar/9110295/&amp;prizes=3"></a></p>
<p><a href="http://www.joeyrivera.com/atlantaphp/prize.php?event=http://www.meetup.com/atlantaphp/calendar/9110295/&amp;prizes=3">http://www.joeyrivera.com/atlantaphp/prize.php?event=http://www.meetup.com/atlantaphp/calendar/9110295/&amp;prizes=3</a></p>
<p>The first link loads all members of atlanta php in meetup.com. The second link loads the atlanta php members that attended the event defined by the event parameter. The last link does the same as the second link but shows a list of the 3 prize winners as well. At the bottom of each page you can click on download to get all the code. If anyone is interested in a technical explanation of what the page is doing feel free to ask here and I&#8217;ll write some more or add comments to the code. Maybe this will get me some comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2008/getting-list-of-members-from-an-event-in-meetupcom-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
