<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Be a PHP Bee</title>
	<atom:link href="http://bephpbee.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bephpbee.wordpress.com</link>
	<description></description>
	<lastBuildDate>Tue, 03 Nov 2009 10:45:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bephpbee.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Be a PHP Bee</title>
		<link>http://bephpbee.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bephpbee.wordpress.com/osd.xml" title="Be a PHP Bee" />
	<atom:link rel='hub' href='http://bephpbee.wordpress.com/?pushpress=hub'/>
		<item>
		<title>SECURED PHP CODING &#8211; Part One</title>
		<link>http://bephpbee.wordpress.com/2009/11/02/secured-php-coding-part-one/</link>
		<comments>http://bephpbee.wordpress.com/2009/11/02/secured-php-coding-part-one/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 11:45:20 +0000</pubDate>
		<dc:creator>bephpbee</dc:creator>
				<category><![CDATA[PHP security]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[security holes]]></category>
		<category><![CDATA[security PHP]]></category>
		<category><![CDATA[site compromise]]></category>
		<category><![CDATA[WRITING SECURE PHP]]></category>

		<guid isPermaLink="false">http://bephpbee.wordpress.com/?p=5</guid>
		<description><![CDATA[This is an article about how to keep your web document as secured as possible while using PHP as a scripting language. PHP is widely used scripting language and most of the developers preferred MySql database as it default to PHP and easy to communicate from PHP.  PHP runs under almost every web server and operating system. List of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bephpbee.wordpress.com&amp;blog=10234081&amp;post=5&amp;subd=bephpbee&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This is an article about how to keep your web document as secured as possible while using PHP as a scripting languag</em>e. PHP is widely used scripting language and most of the developers preferred MySql database as it default to PHP and easy to communicate from PHP.  PHP runs under almost every web server and operating system.</p>
<p><strong>List of basic security issues</strong></p>
<ol>
<li> malicious data from users of the website</li>
<li>default credentials</li>
<li>SQL Injection</li>
<li>predictable path</li>
<li>allow url fopen</li>
</ol>
<p><strong>malicious data from users of the website</strong></p>
<p>First and foremost, If you think about writing a secured web document, you should not trust your user and their inputs to the website as it may contain malicious code. It is not always a malicious user who can exploit a security hole &#8211; problems can just as easily arise because of a user unintentionally doing something wrong.  Expect every single data from the users should be validated at client side as well server side. Javascript is the fair enough to do this client side validation.</p>
<p>In php.ini file you can see register_globals that allow to create global variables and its scope will be throughout the website. It cause some security hole in the document.</p>
<p>if($username == &#8220;john&#8221; &amp;&amp; $password == &#8220;password123&#8243;)</p>
<p>{</p>
<p>$auth = 1;</p>
<p>}else</p>
<p>{</p>
<p>$auth = 0;</p>
<p>}</p>
<p>here the malicious user can pass the $auth value in the url as http://www.sitename.com?auth=1</p>
<p>The first, and perhaps the best, is to set &#8220;register_globals&#8221; to off. The second is to ensure that you only use variables that you have explicitly set yourself. In the above example, that would mean adding &#8220;$auth = 0;&#8221; at the beginning of the script.</p>
<p>Using &#8220;preg_replace&#8221; function, replace the tags and scripts from the user and use &#8220;strip_tags&#8221; before use the inputs.</p>
<p><strong>default credential</strong></p>
<p>By default, mysql username is root and password may be empty. So before start everything change this credentials to non predictable one. If you have hosted your site in shared host then change your control panal,FTP access credentails over the period of time. php.ini have the option to comment the php functions if they are not really used for this particular website.</p>
<p><strong>SQL Injection</strong></p>
<p>The most common security hazard faced when interacting with a database is that of SQL Injection &#8211; when a user uses a security glitch to run SQL queries on your database. Take an example of login system, the common sql will be</p>
<p>mysql_query(&#8220;SELECT Username, Password FROM admin_access WHERE Username = &#8216;&#8221;.$_POST['txt_user'].&#8221;&#8216; and Password = &#8216;&#8221;.$_POST['txt_pass'].&#8221;&#8216;&#8221;);</p>
<p>here this query will be executed in the mysql engine fetch the data from the database if they are valid. In the txt_user is a text filed where the users will try to inject their code to compromise your site as below</p>
<p>they will type <strong>&#8216; OR a = a # </strong>in the user text box, then the sql query will be</p>
<p>SELECT Username, Password FROM admin_access WHERE Username = &#8221; OR a=a # and Password = &#8217;123456&#8242;</p>
<p>so userame = empty or a=a(this is always true) and mysql stop reading after # symbol as it mean that after which they are commented. So this query will return all the values from the admin_access table and most of the developer used to have the first record as super admin&#8217;s details. So the hackers job will be a easiest one to compromise your admin area.</p>
<p>solution</p>
<div id="_mcePaste">function check_login_input($value)</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">if (get_magic_quotes_gpc())</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">$value = stripslashes($value);</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">$value = mysql_real_escape_string($value);</div>
<div id="_mcePaste">return $value;</div>
<div id="_mcePaste">}</div>
<div>
<div>$username = check_login_input($_POST['txt_user']);</div>
<div>$password = check_login_input($_POST['txt_pass']);</div>
<div>$check = mysql_query(&#8220;SELECT Username, Password FROM admin_access WHERE Username = &#8216;&#8221;.$username.&#8221;&#8216; and Password = &#8216;&#8221;.$password.&#8221;&#8216;&#8221;);</div>
</div>
<div>Now, unless you happen to have a user with a very unusual username and a blank password, your malicious attacker will not be able to do any damage at all. It is important to check all data passed to your database like this, however secure you think it is. HTTP Headers sent from the user can be faked. Their referral address can be faked. Their browsers User Agent string can be faked. Do not trust a single piece of data sent by the user, though, and you will be fine.</div>
<div><strong>predictable path</strong></div>
<div><strong> </strong></div>
<div>Should not use the predictable path like &#8221; includes,images,admin&#8221;  so on.. So the hackers easily predict this folders and this folders may contain some valuable files like database connections or something about may disclose the server details. Avoid use .php extension rather using .inc. inc will display your username, password or db hosting details in the browser. But php just execute and display the result only. Each folder should be enabled directory listing denied and each folder should have index file to redirect to error page if the hack to see the list of files in the directory.</div>
<div><strong>allow url fopen</strong></div>
<div>unless if allow url fopen really not used in the website, you should keep it off in the php.ini settings or through .htaccess. Other wise it helps the hackers to read and write in your files.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bephpbee.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bephpbee.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bephpbee.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bephpbee.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bephpbee.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bephpbee.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bephpbee.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bephpbee.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bephpbee.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bephpbee.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bephpbee.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bephpbee.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bephpbee.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bephpbee.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bephpbee.wordpress.com&amp;blog=10234081&amp;post=5&amp;subd=bephpbee&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bephpbee.wordpress.com/2009/11/02/secured-php-coding-part-one/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6730ad3b7ef55567e1e8ebc7bb5d3bc7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bephpbee</media:title>
		</media:content>
	</item>
	</channel>
</rss>
