<?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>Webdevelopment at huuah.com &#187; php</title>
	<atom:link href="http://huuah.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://huuah.com</link>
	<description>webdevelopment, cms, php, javascript etc</description>
	<lastBuildDate>Sun, 20 Nov 2011 20:30:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>A simple login script with PHP and MySQL</title>
		<link>http://huuah.com/a-simple-login-script-with-php-and-mysql/</link>
		<comments>http://huuah.com/a-simple-login-script-with-php-and-mysql/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 17:45:29 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=417</guid>
		<description><![CDATA[<p>With this guide I will try to go through the very basic techniques of making a simple php script that can handle login authorization of website users.</p>
<p>The guide will be based on common Linux installations of both MySQL and PHP.</p>
<a name="Step+1+%26%238211%3B+the+database"></a>Step 1 &#8211; the database
<p>Create a table&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>With this guide I will try to go through the very basic techniques of making a simple php script that can handle login authorization of website users.</p>
<p>The guide will be based on common Linux installations of both MySQL and PHP.</p>
<a name="Step+1+%26%238211%3B+the+database"></a><h1>Step 1 &#8211; the database</h1>
<p>Create a table in your MySQL database with 2 fields, <code>username</code> and <code>password</code>. This could be done by running the following code in your MySQL shell or from phpMyAdmin or another interface:</p>
<pre class="brush: plain; title: ; notranslate">
CREATE TABLE `login` (
`username` TEXT NOT NULL ,
`password` TEXT NOT NULL
)
</pre>
<p>The database table called <code>login</code> is now created with 2 field named <code>username</code> and <code>password</code>.</p>
<a name="Step+2+%26%238211%3B+The+HTML+form"></a><h1>Step 2 &#8211; The HTML form</h1>
<p>First we have to create the web formula to show the login function:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;form action=&quot;login.php&quot; method=&quot;post&quot;&gt;
  &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;
  &lt;input type=&quot;password&quot; name=&quot;password&quot;&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Login&quot;&gt;
&lt;/form&gt;
</pre>
<p>This will output 3 field like this:</p>
<form action="#" method="post" onsubmit="return false;">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Login">
</form>
<p>When submitting the form, either by hitting enter or by clicking the Login button, the formula will send the username and password to the login.php file.</p>
<a name="Step+3+%26%238211%3B+Getting+the+information+from+the+website."></a><h1>Step 3 &#8211; Getting the information from the website.</h1>
<p>The login information has now been sent to the login.php and we have to receive these value before checking them against the MySQL database.</p>
<p>Login.php:</p>
<pre class="brush: php; title: ; notranslate">
  &lt;?php
  ...
  // receiveing the login information
  $username = $_GET[&quot;username&quot;];
  $password = $_GET[&quot;password&quot;];
  ?&gt;
</pre>
<a name="Step+4+%26%238211%3B+Connecting+to+the+database"></a><h1>Step 4 &#8211; Connecting to the database</h1>
<p>Before checking the login data against the database, we have to open a new connection.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
  ...
  //login information to the MySQL database
  $dbuser = &quot;myUsername&quot;; // change myUsername to your own username
  $dbpass = &quot;myPassword&quot;; //change myPassword to your own password
  $dbhost = &quot;localhost&quot;; // this should work in most cases. Otherwise contact your webhost
  $db = &quot;myDatabase&quot;; // change myDatabase to your the database assigned to your login

  // perform user authentication
  mysql_connect($server, $dbuser, $dbpass);
  // selecting database
  mysql_select_db($db;

  ...
?&gt;
</pre>
<a name="Step+5+%26%238211%3B+Comparing+the+username+and+password+against+the+database"></a><h1>Step 5 &#8211; Comparing the username and password against the database</h1>
<p>We have the login information from the formula and we have opened a connection to the database. Great. All we have to do, is the actually user validation.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
  ..
  // check the content of our $username and $password variable against the login table
  $sql = &quot;SELECT username FROM login WHERE username='$username' AND password='$password'&quot;;
  // perform the query
  $query = mysql_query($sql);
  // check if the request returned 1 or 0 rows from the database
  if (mysql_num_rows($query)) {
    // 1 or more rows matched our request, which means the username and password combo are valid
  } else {
    // 0 rows matched our request. Login is not valid then.
  }
  ..
?&gt;
</pre>
<a name="Step+6+%26%238211%3B+All+done%2C+final+pointer"></a><h1>Step 6 &#8211; All done, final pointer</h1>
<p>This is a very basic type of php login script. There are a lot of other things to have in mind when making database queries, that I have not convert in the above examples:</p>
<ul>
<li>Perhaps the login table should hold more information, like a user id for easier validation later on the the script.</li>
<li>Double checking and validating user input to prevent SQL Injection. This could be done be PHP Magic Quotes or by manually applying addslashes() and stripslashs().</li>
<li>..</li>
</ul>
<p>But then again. Very simple demonstration.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/a-simple-login-script-with-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Point in polygon with php</title>
		<link>http://huuah.com/point-in-polygon-with-php/</link>
		<comments>http://huuah.com/point-in-polygon-with-php/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 09:27:36 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[point]]></category>
		<category><![CDATA[polygon]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=395</guid>
		<description><![CDATA[<p>Have you ever had the need to check if a specific coordinate (point) is located inside or outside a polygon shaped area? I never did, so I had to found out how to automate this process, so I didn&#8217;t have to do this by hand. </p>
<p>The problem with this&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Have you ever had the need to check if a specific coordinate (point) is located inside or outside a polygon shaped area? I never did, so I had to found out how to automate this process, so I didn&#8217;t have to do this by hand. </p>
<p>The problem with this kind of assignment is, that I did not know what to search for on Google. Hadn&#8217;t though of it, as being a point in a polygon shaped area. I tried searching with words like &#8216;coordinate inside area&#8217;, &#8216;longitude latititude in area&#8221; and things like that, without much luck. Then a guy on IRC suggested a search for &#8220;point in polygon&#8221; and wuhu. Bingo.</p>
<p>I then found this page: <a href="http://www.assemblysys.com/dataServices/php_pointinpolygon.php">point in polygon</a>, where the author has posted a PHP class that does all the hard work for you. Brilliant.</p>
<p>I have a database table in MySQL containing x and y coordinates for a number of different points. In another table a have coordinates for a number of polygon shapes and I then want to check which point are located inside which polygons.</p>
<p>This is actually pretty simple to do.</p>
<p>Lets say we have a point (2,2) and want to check if this is inside a polygon with these coordinates (1,1), (3,6), (4,0):</p>
<pre class="brush: php; title: ; notranslate">

  //include the point in the polygon classs
  include_once(&quot;point_in_polygon.php&quot;);

  $point = &quot;2 2&quot;;
  $polygon = array(&quot;1 1&quot;, &quot;3 6&quot;, &quot;4 0&quot;)

  $pointLocation = new pointLocation();
  print &quot;Point in &quot; . $pointLocation-&gt;pointInPolygon($point, $polygon) . &quot; the polygon&quot;;
</pre>
<p><em>(NB: remember to arrange the coordinates in a clockwise direction, as counterclockwise returns incorrect results. Thanks to carson, for this tip).</em></p>
<p>Run the code and it will print:</p>
<pre class="brush: plain; title: ; notranslate">
$ php polygon.php
Point is inside the polygon
</pre>
<p><strong>So how does this work?</strong> All you have to do, is to &#8220;draw&#8221; a straight line from the point and all the way through the shape and then count have many lines you cross. If you cross an even or zero number of lines the point is outside the shape and if the number the uneven you are inside. </p>
<p><strong>Got it?</strong> Well, there&#8217;s some quick drawings from Gimp to illustrate it:</p>
<p>The example from the above code:<br />
<img src="http://huuah.com/images/2-2-inside.jpg" alt="point in polygon inside" /></p>
<p>Point is inside because of a uneven number of line crosses:<br />
<img src="http://huuah.com/images/1-cross-inside.jpg" alt="point in polygon inside" /></p>
<p>Point is outside because of a even or zero number of line crosses:<br />
<img src="http://huuah.com/images/2-cross-outside.jpg" alt="point in polygon outside" /></p>
<p><strong>There you go.</strong> This is one way to check if a point is inside a polygon shaped area.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/point-in-polygon-with-php/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

