<?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>Why So Scared &#187; PHP</title>
	<atom:link href="http://www.whysoscared.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.whysoscared.com</link>
	<description>A blog about; Programming, Music and Random Stuff</description>
	<lastBuildDate>Thu, 10 Jun 2010 02:43:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP function check if a file (or url exists)</title>
		<link>http://www.whysoscared.com/php-function-check-if-a-file-or-url-exists/</link>
		<comments>http://www.whysoscared.com/php-function-check-if-a-file-or-url-exists/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 21:41:54 +0000</pubDate>
		<dc:creator>Juo</dc:creator>
				<category><![CDATA[tidbit]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.whysoscared.com/?p=129</guid>
		<description><![CDATA[While doing some scripting for Warez-DnB (for a new feature that ill talk more about soon) I needed a script that would check if a file on the server existed.
The PHP code below does this job perfectly, returning a boolean TRUE if the file is found and FALSE if it isn&#8217;t .

function url_exists($url) {
// Version [...]]]></description>
			<content:encoded><![CDATA[<p>While doing some scripting for <a href="http://warez-dnb.com/" target="_blank">Warez-DnB</a> (for a new feature that ill talk more about soon) I needed a script that would check if a file on the server existed.</p>
<p>The PHP code below does this job perfectly, returning a boolean TRUE if the file is found and FALSE if it isn&#8217;t .</p>
<blockquote>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">function url_exists($url) {</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">// Version 4.x supported</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">$handle   = curl_init($url);</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">if (false === $handle)</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">return false;</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">curl_setopt($handle, CURLOPT_HEADER, false);</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">curl_setopt($handle, CURLOPT_HTTPHEADER, Array(&#8221;User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15&#8243;) ); // request as if Firefox</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">curl_setopt($handle, CURLOPT_NOBODY, true);</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">$connectable = curl_exec($handle);</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">curl_close($handle);</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">return $connectable;</div>
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
</blockquote>
<blockquote><p>function url_exists($url) {</p>
<p>// Version 4.x supported</p>
<p>$handle   = curl_init($url);</p>
<p>if (false === $handle)</p>
<p>{</p>
<p>return false;</p>
<p>}</p>
<p>curl_setopt($handle, CURLOPT_HEADER, false);</p>
<p>curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works</p>
<p>curl_setopt($handle, CURLOPT_HTTPHEADER, Array(&#8221;User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15&#8243;) ); // request as if Firefox</p>
<p>curl_setopt($handle, CURLOPT_NOBODY, true);</p>
<p>curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);</p>
<p>$connectable = curl_exec($handle);</p>
<p>curl_close($handle);</p>
<p>return $connectable;</p>
<p>}</p></blockquote>
<p>I thought someone else might find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.whysoscared.com/php-function-check-if-a-file-or-url-exists/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Image Watermarking</title>
		<link>http://www.whysoscared.com/php-image-watermarking/</link>
		<comments>http://www.whysoscared.com/php-image-watermarking/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 14:13:45 +0000</pubDate>
		<dc:creator>Juo</dc:creator>
				<category><![CDATA[tidbit]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.whysoscared.com/?p=107</guid>
		<description><![CDATA[If you&#8217;ve ever wanted to watermark images on your website, this neat script will be just what you&#8217;re looking for.
The watermark image is held in a separate file, rather than having to actually edit each image with your watermark, save and upload, this script will serve the watermark to the user on the image as [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever wanted to watermark images on your website, this neat script will be just what you&#8217;re looking for.</p>
<div id="attachment_108" class="wp-caption alignright" style="width: 147px"><a href="http://www.whysoscared.com/wp-content/uploads/2009/06/watermark.png"><img class="size-full wp-image-108" src="http://www.whysoscared.com/wp-content/uploads/2009/06/watermark.png" alt="Warez-DnB watermark" width="137" height="119" /></a><p class="wp-caption-text">The Warez-DnB Watermark</p></div>
<p>The watermark image is held in a separate file, rather than having to actually edit each image with your watermark, save and upload, this script will serve the watermark to the user on the image as  and when its requested.</p>
<p>I like this approach to watermarking because no only is it much easier than editing each picture individually it also means with FTP access you still have an original image intact without the watermark. Only users connecting via HTTP will see the watermarked version.</p>
<p>This also allows for ultimate flexibility, if for whatever reason you decide to change the site logo, its as simple as replacing one image file and <em>every</em> image hosted will have the new watermark.</p>
<p><span id="more-107"></span></p>
<p>Save this simple PHP script below as &#8220;<a href="http://pastie.org/private/g1asingn98laxfugbu6etw" target="_blank">watermark.php</a>&#8221;</p>
<p>The final stage is uploading the watermark.php file and image into the directory you want watermarking to take place. In the case of Warez-DnB this is in h<a href="http://www.warez-dnb.com/grabs/">ttp://www.warez-dnb.com/grabs/</a></p>
<p>The final step is an edit to the .htaccess file</p>
<blockquote><p><code>RewriteEngine On<br />
RewriteCond %{REQUEST_FILENAME} -f<br />
RewriteRule \.(gif|jpeg|jpg|png)$ watermark.php [QSA,NC]</code></p></blockquote>
<p>If you wanted to use the directory /images/ you should now have</p>
<p>/images/watermark.php<br />
/images/watermark.png<br />
/images/.htaccess</p>
<p>Now start uploading some images to /images/ and all is done.</p>
<p>Example <a href="http://www.warez-dnb.com/grabs/71a3007301fbd4349e99d85d7afd1c3b.png" target="_blank">http://www.warez-dnb.com/grabs/71a3007301fbd4349e99d85d7afd1c3b.png</a></p>
<p>Enjoy <img src='http://www.whysoscared.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.whysoscared.com/php-image-watermarking/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
