<?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>Not A n00b &#187; php</title>
	<atom:link href="http://notan00b.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://notan00b.com</link>
	<description>Tutorials, Scripts, and Rants</description>
	<lastBuildDate>Wed, 12 May 2010 08:08:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working with WHMCS</title>
		<link>http://notan00b.com/2010/03/working-with-whmcs/</link>
		<comments>http://notan00b.com/2010/03/working-with-whmcs/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 03:36:12 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WHMCS]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=304</guid>
		<description><![CDATA[Well I don&#8217;t plan on writing a lot here, but I will let you know that I am currently working with WHMCS (a client management software) and programming a couple add-ons.  WHMCS is a great piece of software, but does make it difficult to use their functions.  For anyone out there looking to [...]]]></description>
			<content:encoded><![CDATA[<p>Well I don&#8217;t plan on writing a lot here, but I will let you know that I am currently working with WHMCS (a client management software) and programming a couple add-ons.  WHMCS is a great piece of software, but does make it difficult to use their functions.  For anyone out there looking to program something for WHMCS, my best piece of advice would be to use the examples, and then go over EVERY piece of documentation and example modules they have.  The nice thing about WHMCS is the simple fact that they don&#8217;t have any strict php rules.  I have programmed modules for Joomla and Drupal and a couple others, and I found it very time consuming to look up their documentation and how to add stuff to the database their way.  The up side to extensive documentation is that they have the work done for you.  You can send emails relatively simply to specific members, or grab user info very easily.  That is the downside to WHMCS.  You have to code extra lines to send out an email properly, or do trial and error to find the user information.  I plan on posting a little more in depth tutorial once I finish the add on I am currently working on.  Until then!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2010/03/working-with-whmcs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is a BLIND SQL Injection?</title>
		<link>http://notan00b.com/2010/01/what-is-a-blind-sql-injection/</link>
		<comments>http://notan00b.com/2010/01/what-is-a-blind-sql-injection/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 07:34:20 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[1=1]]></category>
		<category><![CDATA[1=2]]></category>
		<category><![CDATA[blind sql]]></category>
		<category><![CDATA[blind sql injection]]></category>
		<category><![CDATA[bsi]]></category>
		<category><![CDATA[get variables]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=241</guid>
		<description><![CDATA[Its been awhile, and I have been pretty busy.  I decided to talk a little bit about a few things I have learned and been working on.  When it comes to website security, most programmers understand what SQL injections are.  The user types something into a form that manipulates the SQL statement [...]]]></description>
			<content:encoded><![CDATA[<p>Its been awhile, and I have been pretty busy.  I decided to talk a little bit about a few things I have learned and been working on.  When it comes to website security, most programmers understand what SQL injections are.  The user types something into a form that manipulates the SQL statement to give them access to certain areas or display the info they want.  Then there are Blind Sql Injections (BSI).  These are much more complicated and considered an advanced penetration technique.  The funny thing is, they are 100% preventable.</p>
<p>So lets start out with the basics, what is it?  It all has to do with the URL bar and <em>get</em> variables.  Let&#8217;s say that my site is &#8220;http://www.mysite.com/&#8221; and I created a script that grabs info out of my database based on it&#8217;s ID in the database.  For example:  &#8220;http://www.mysite.com/index.php?pageid=10&#8243;.  My SQL statement will look like this: &#8220;SELECT * FROM pages WHERE ID=$_GET[id]&#8220;.  Just like a regular SQL Injection, a hacker can submit malicious code using the <em>get</em> variable.</p>
<p>This is where we differ a little from a basic SQL Injection.  In a basic SQL Injection, you simply type <code>' or 'x'='x</code> into a form and it may or may not authenticate you.  Your goal is to get it to toss an error, so that you know your code is not being parsed correctly.</p>
<p>Because we are retrieving info about a page with my example website script, not users, it makes it difficult to authenticate yourself with one line of code like a basic SQL Injection.  There is one thing we can do, and that is to make the SELECT statement true or false.  If my site is vulnerable, all we would need to type in the browser is: &#8220;http://www.mysite.com/index.php?pageid=10 and 1=1&#8243;.  If it isn&#8217;t parsed correctly, my vulnerable code will now look like this: SELECT * FROM pages WHERE ID=10 and 1=1.  That is a true statement so our page will display normally.  Now we try a false statement: &#8220;http://www.mysite.com/index.php?pageid=10 and 1=2&#8243; and our SQL query reads as: SELECT * FROM pages WHERE ID=10 and 1=2.  This statement is false, so it will not grab ANY info from pages.  With no info being grabbed from the database, our page will look significantly different.  Maybe some pictures won&#8217;t be there, or text will be missing, or maybe the entire page will be blank.  If that is the case, then you are in business.</p>
<p>So why is it called BLIND Sql Injection?  Well rather than executing queries directly, like a regular SQL injection, and getting your info directly, you are now blind instead.  You are using true/false statements to guess what the table names are, or manually hash them out using ascii codes and substrings.  It can take hours to get access to a vulnerable site, but there are programs and scripts out there that will do all the work for you so you don&#8217;t even have to think about it.</p>
<p>If you want to know a little bit more about how this works, lets try it out on a vulnerable example: http://www.cblpi.org</p>
<p>Lets say I went to Ann Coulter&#8217;s bio page: http://www.cblpi.org/programs/bio.cfm?ID=15&#038;type=Speaker</p>
<p>We notice that ID=15 and may be vulnerable.  So we test it by typing: http://www.cblpi.org/programs/bio.cfm?ID=15 and 1=1&#038;type=Speaker</p>
<p>Nothing changes!  Let&#8217;s test it again by typing 1=2: http://www.cblpi.org/programs/bio.cfm?ID=15 and 1=2&#038;type=Speaker</p>
<p>Now a blank page appears, so we know that the ID variable isn&#8217;t being parsed correctly.</p>
<p>Lets figure out what version of MySQL it is using BSI using @@version: http://www.cblpi.org/programs/bio.cfm?ID=15 and substring(@@version,1,1)=5&#038;type=Speaker</p>
<p>If its version 5.xxxx it will show up as true!  Does it? No.  Then lets try 4: http://www.cblpi.org/programs/bio.cfm?ID=15 and substring(@@version,1,1)=4&#038;type=Speaker</p>
<p>And know we know they are using version 4.xxxx of MySQL.</p>
<p>Lets try guessing a table name! http://www.cblpi.org/programs/bio.cfm?ID=15 and (select 1 from USERS limit 0,1)=1&#038;type=Speaker</p>
<p>If table USERS exists, it will return 1 and the statement will be TRUE!  Does it?  No it doesn&#8217;t, but it does give us a nice error page saying it doesn&#8217;t exist, with the table name that we are currently selecting out of (PEOPLE).  </p>
<p>So lets validate the code real quick.  We know PEOPLE does exist, so http://www.cblpi.org/programs/bio.cfm?ID=15 and (select 1 from PEOPLE limit 0,1)=1&#038;type=Speaker should be true.</p>
<p>And it is! The page displays normally.  </p>
<p>You can bruteforce guess the table names, or there are many round about ways of detecting them letter by letter using substring and ascii functions.  And once you figure out where the good information is stored, then you can break into those tables and grab it.  </p>
<p>I&#8217;m not here to give you the exact methods on how to bruteforce it or use char codes, but just to give you the basics on what it is.  Know that you know what it is, protect against it!  How hard is it to check for a space? Add slashes? Check if it is an int?  Guys common, these practices are standard when dealing with forms, why not make them standard when dealing with <em>get</em> variables.  Recently (about 4-6 months ago) HyperVM was found to have a BSI vulnerability and within a couple of days, thousands and thousands of VPS servers were hacked and accounts deleted.  It all could have been prevented with just one line of code.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2010/01/what-is-a-blind-sql-injection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP to create website thumbnails</title>
		<link>http://notan00b.com/2009/09/php-to-create-website-thumbnails/</link>
		<comments>http://notan00b.com/2009/09/php-to-create-website-thumbnails/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 00:46:20 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[frontpage]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[internetexplorer]]></category>
		<category><![CDATA[internetexplorer.application]]></category>
		<category><![CDATA[nails]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[shot]]></category>
		<category><![CDATA[thumb]]></category>
		<category><![CDATA[thumbnails]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webpage]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=230</guid>
		<description><![CDATA[Want to know how to create a thumbnail/screen shot of a webpage using PHP?  Well check it out here]]></description>
			<content:encoded><![CDATA[<p>Bing.com has an awesome feature that is popping up more and more all over the internet.  Most websites charge for this, as they should.  It isn&#8217;t something that can be done on a normal hosting plan, but can only be done (this way) on a Windows server, where Internet Explorer is installed and you have access to.  There are several ways to do this on Linux servers, but I am going to cover the Windows version.</p>
<p>In order to create an image for a thumbnail, we need to take a screen shot of webpage.  PHP GD class allows us to take screen shots of different windows.  PHP also allows us to control different windows, like Internet Explorer using the COM class.  So basically what we need to do is have PHP open up a window in Internet Explorer, navigate to a website, and then take a picture of that window, then save it/display it.  The tutorial shown on php.net shows exactly how to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.libgd.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Still working? */</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Busy</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">com_message_pump</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagegrabwindow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Quit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;iesnap.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>So this is SUPPOSED to load libgd.org and take a snap shot and save it to &#8220;iesnap.png&#8221;, and it DOES work, but only if your server allows it to work.  If it doesn&#8217;t you just get a black/blank picture.  </p>
<p>Windows rarely lets one program access another program via the desktop and control it.  By default, Apache isn&#8217;t allowed to open Internet Explorer on windows, so we have to add an exception.  </p>
<ol>
<li>On Vista, click the start button, and in the search box type &#8220;Services&#8221;.  </li>
<li>At the very top, there should be a link under Programs called Services.  Click that link. </li>
<li>It will open up all running services, and you will see Apache running (mine is Apache 2.2, and is the first entry).</li>
<li>Right click on it and select &#8220;Properties&#8221;</li>
<li>Navigate to the &#8220;Log On&#8221; tab</li>
<li>Click the box for &#8220;Allow service to interact with the desktop&#8221;</li>
<li>Save it and close the properties</li>
<li>Right click on Apache again</li>
<li>This time, click restart, and Apache will be restarted with the new features</li>
</ol>
<p>Now run your script again!  Vista pops up a little box alerting the user that a program is interact with the desktop.  Just ignore it and it will disappear in a few seconds.  After the program is complete, go to your web folder and you will see iesnap.png is now an image of a webpage!</p>
<p>Time to make some tweaks!  You will notice that it grabs the ENTIRE screen, meaning the tool bars and everything.  We will need to make a few adjustments to get rid of those.  The first one I made was to make the browser show as a full screen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FullScreen</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>That last line will make it display in the fullscreen mode, which takes care of the tool bars at the top, but I still see the footer and the side bar that I want to get rid of.  In order to do this, we need to crop a little, but GD doesn&#8217;t have a simple cropping method.  What I did was copied part of this picture to a new picture and resized it.  Keep in mind, my display settings are going to be different, and will require you to look at your picture and test it out:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$w</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$h</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;www.notan00b.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1263</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$w</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">780</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$h</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FullScreen</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/* Still working?*/</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Busy</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">com_message_pump</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagegrabwindow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Quit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;iesnap.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Copy</span>
<span style="color: #990000;">imagecopyresized</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">780</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output and free from memory</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>There we have it.  Even with the GET variables so you can reuse this script for AJAX or any HTML document.  My images were 1280&#215;800.  To remove the bars I scaled it down to 1263&#215;780, and they were removed almost perfectly, but it will be different for everyone.</p>
<p>I would post an example of it, but I am only hosted&#8230; I don&#8217;t actually pay for a VPS or private server just for one little blog.  Sorry folks.  If it was up to me, and I needed this service, I would probably pay a company to do it for me for a simple little website.  If you have a VPS with enough memory, this may work for you.  Good luck, let me know if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/09/php-to-create-website-thumbnails/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WhosOnline Tutorial now online!</title>
		<link>http://notan00b.com/2009/09/whosonline-tutorial-now-online/</link>
		<comments>http://notan00b.com/2009/09/whosonline-tutorial-now-online/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 21:19:53 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[whosonline]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=227</guid>
		<description><![CDATA[With the success of the WhosOnline PHP script, I have made a quick and simple tutorial on how to use it for whatever you decide.  It is really easy and can be used to do anything from displaying the total number of people online, to displaying all the members names individually.  Take a [...]]]></description>
			<content:encoded><![CDATA[<p>With the success of the WhosOnline PHP script, I have made a quick and simple tutorial on how to use it for whatever you decide.  It is really easy and can be used to do anything from displaying the total number of people online, to displaying all the members names individually.  <a href="http://notan00b.com/tutorials/">Take a look at it in the Tutorials section!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/09/whosonline-tutorial-now-online/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery, PHP, and Forms</title>
		<link>http://notan00b.com/2009/09/jquery-php-and-forms/</link>
		<comments>http://notan00b.com/2009/09/jquery-php-and-forms/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 01:56:57 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[box]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[edit]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[hidden]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=204</guid>
		<description><![CDATA[I decided to put up a quick post on how I have been using jQuery and PHP to process forms for me very easily.  To get started, let me give you a background on what I have been trying to do.  I have a page with a list of info, and I wanted [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to put up a quick post on how I have been using jQuery and PHP to process forms for me very easily.  To get started, let me give you a background on what I have been trying to do.  I have a page with a list of info, and I wanted to give the user the option of editing that info using jQuery&#8217;s built in dialog box because it is awesome looking.  There were a few ways to go about doing this, which is what I am going to describe.</p>
<h1>This is the goal!</h1>
<li>I click the link</li>
<li>A dialog box pops up</li>
<li>The text boxes have info filled in already</li>
<li>Something like this:<br />Name:<br />
<input type="text" value="Bob Jones"/></li>
<li>I can edit it, then submit it</li>
<li>I want the code to be small</li>
<p>The first way that I thought of was to create a form for every piece of info I pulled from the database.  So lets say for ID=1, there would be 1 form with all the info preloaded into it.  ID=2 would be a separate form with all different info.  This works, but I had to have about 20 dialog boxes per page, and it would cause the HTML output to be about 20 times larger than I needed.</p>
<p>In my head, I knew there had to be a way to do this with DHTML and jQuery, and I finally figured it out.  All I had to do was create a value and store it in the button that I was already using (well it was actually just a link).  So I turned <code>&lt;a href="#" class="editThis"&gt;Edit!&lt;/a&gt;</code> into <code>&lt;a href="#" class="editThis" id="1"&gt;Edit!&lt;/a&gt;</code>.  I used PHP to echo out the data already but now each link will have a different ID:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>#<span style="color: #000099; font-weight: bold;">\&quot;</span> class<span style="color: #000099; font-weight: bold;">\&quot;</span>editThis<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$row[UserId]</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Edit!&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now we have 20 links, each looking the same, but each with a unique ID.  This is where jQuery comes in handy.  We can look up the anchor by class, and then store the ID as a variable for later use!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.editThis&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> id<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now we have the ID of the info we want to manipulate.  The next part was a little more difficult to figure out.  I want only 1 dialog box and 1 form, but want the info auto filled.  At first I was thinking we needed to do a lot of AJAX to pull out each and every variable that we want to edit, but then I figured out we could pass that info into HTML as a &#8220;HIDDEN&#8221; variable.  HTML is great because you can hide all sorts of stuff and the user will never see it.  I can set the style as &#8220;hidden&#8221;, or I can include it inside a tag somewhere, or better yet, and my favorite, I can create a hidden variable: <code>&lt;input type="hidden" id="editinfo1" value="myinfohere"&gt;</code>  Now we need to implement this into our PHP to write it to the HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>#<span style="color: #000099; font-weight: bold;">\&quot;</span> class<span style="color: #000099; font-weight: bold;">\&quot;</span>editThis<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$row[UserId]</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Edit!&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>hidden<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; name=<span style="color: #000099; font-weight: bold;">\&quot;</span>editinfo<span style="color: #006699; font-weight: bold;">{$row['UserId']}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; id=<span style="color: #000099; font-weight: bold;">\&quot;</span>editinfo<span style="color: #006699; font-weight: bold;">{$row['UserId']}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; value=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$row[Name]</span>::<span style="color: #006699; font-weight: bold;">$row[Address]</span>::<span style="color: #006699; font-weight: bold;">$row[Age]</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now our HTML will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;#&quot; class=&quot;editThis&quot; id=&quot;1&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;editinfo1&quot; id=&quot;editinfo1&quot; value=&quot;Bob Jones::123 N Street::26&quot;&gt;</pre></div></div>

<p>All our info is now conveniently stored for jQuery to access later!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.editThis&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> id<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> variables<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#editinfo&quot;</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> info<span style="color: #339933;">=</span>variables.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'::'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">+</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">+</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now for the fun part, using jQuery to dynamically change the values of our SINGLE form!<br />
Our form might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;dialog&quot; title=&quot;Edit User&quot;&gt;
    &lt;form method=&quot;post&quot; name=&quot;edituserform&quot; action=editUser.php&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;edituser&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;userid&quot; id=&quot;euid&quot; value=&quot;0&quot;&gt;
    &lt;center&gt;
        &lt;table width=&quot;75%&quot;&gt;
            &lt;tr&gt;
                &lt;td align=&quot;right&quot;&gt;User Name: &lt;/td&gt;
                &lt;td align=&quot;left&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;eusername&quot;&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td align=&quot;right&quot;&gt;Address: &lt;/td&gt;
                &lt;td align=&quot;left&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;address&quot; id=&quot;eaddress&quot;&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td align=&quot;right&quot;&gt;Age: &lt;/td&gt;
                &lt;td align=&quot;left&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;age&quot; id=&quot;eage&quot;&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/center&gt;
    &lt;/form&gt;
&lt;/div&gt;</pre></div></div>

<p>And our jQuery would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.editThis&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> id<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> variables<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#editinfo&quot;</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> info<span style="color: #339933;">=</span>variables.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'::'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#eusername&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#eaddress&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#eage&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;euid&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#dialog&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;open&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#dialog'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dialog</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        autoOpen<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
        width<span style="color: #339933;">:</span> <span style="color: #CC0000;">600</span><span style="color: #339933;">,</span>
        modal<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        position<span style="color: #339933;">:</span> <span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span>
        buttons<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #3366CC;">&quot;Update user&quot;</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                document.<span style="color: #660066;">edituserform</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
            <span style="color: #3366CC;">&quot;Cancel&quot;</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
                $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;close&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #009900;">&#125;</span> 
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That&#8217;s it!  Hopefully it was easy to understand.  Let me know if you need anything cleared up a little!  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/09/jquery-php-and-forms/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial [Part 2] underway!</title>
		<link>http://notan00b.com/2009/08/php-tutorial-part-2-underway/</link>
		<comments>http://notan00b.com/2009/08/php-tutorial-part-2-underway/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 20:08:21 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[2]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[part]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=201</guid>
		<description><![CDATA[Its been a while since I got an update up.  I started working on the second part of my PHP tutorial.  I plan on covering functions, arrays, and get/post variables for now.  I will probably have a third part eventually covering advanced topics like classes, sessions, cookies, files, mysql, and stuff like [...]]]></description>
			<content:encoded><![CDATA[<p>Its been a while since I got an update up.  I started working on the second part of my PHP tutorial.  I plan on covering functions, arrays, and get/post variables for now.  I will probably have a third part eventually covering advanced topics like classes, sessions, cookies, files, mysql, and stuff like that.  For now though, I am going to finish the basics.  I posted the first draft in the tutorial section.  I will update it for the next couple days until I get it completed to my satisfaction.  Check it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/php-tutorial-part-2-underway/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Database Tutorial posted!</title>
		<link>http://notan00b.com/2009/08/wordpress-database-tutorial-posted/</link>
		<comments>http://notan00b.com/2009/08/wordpress-database-tutorial-posted/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 19:18:37 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[creation]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp-db.php]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=190</guid>
		<description><![CDATA[I just created an in depth tutorial that covers the entire wp-db.php file and how WordPress uses it, and how to use it to create plug-ins for WordPress.  It is posted in the tutorials section, here.  Check it out and let me know what you think.
]]></description>
			<content:encoded><![CDATA[<p>I just created an in depth tutorial that covers the entire wp-db.php file and how WordPress uses it, and how to use it to create plug-ins for WordPress.  It is posted in the tutorials section, <a href="http://notan00b.com/tutorials/">here</a>.  Check it out and let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/wordpress-database-tutorial-posted/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>More with PHP Classes</title>
		<link>http://notan00b.com/2009/08/more-with-php-classes/</link>
		<comments>http://notan00b.com/2009/08/more-with-php-classes/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 20:13:19 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[employee]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=184</guid>
		<description><![CDATA[I got a comment on my PHP OOP tutorial to explain how to relate what I taught to real life scenarios.  His scenario was Human Resources Information.  The first thing we will need to decide is what info is important, so lets list a few items:

First name
Last Name
Social Security Number
Address
City
State
Zip
Date of birth
Salary
Position
Start Date

That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I got a comment on my PHP OOP tutorial to explain how to relate what I taught to real life scenarios.  His scenario was Human Resources Information.  The first thing we will need to decide is what info is important, so lets list a few items:</p>
<ul>
<li>First name</li>
<li>Last Name</li>
<li>Social Security Number</li>
<li>Address</li>
<li>City</li>
<li>State</li>
<li>Zip</li>
<li>Date of birth</li>
<li>Salary</li>
<li>Position</li>
<li>Start Date</li>
</ul>
<p>That&#8217;s probably sufficient for our purposes, and then some.  So the next question we need to ask is, what are we planning on doing with this info?  I would assume a lot of it would be interacting with a database.  This would probably involve a lot of CRUD operations (Create, Read, Update, Delete).  So we need to make functions for each.  One to create a new employee in the database, one to get employee info, one to update employee info if it is changed, one to delete employees once they have been fired or never completed training or whatever.  The one other thing I can think of is maybe assigning an employee an ID so he can easily be tracked in the system, in case there are two Mr. John Smith employees.  Speaking of searching, maybe a search function would be nice as well.  So lets set out to create our class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Employee
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$Id</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$FirstName</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$LastName</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$DOB</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$Position</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$Salary</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$StartDate</span><span style="color: #339933;">=</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m/d/Y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$EndDate</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">function</span> _construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">!=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LoadEmployee</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> LoadEmployee<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">/*** Connect to database  ***/</span>
        <span style="color: #666666; font-style: italic;">/*** Code Not Included ***/</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT FROM Employees WHERE Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//makes sure the user exists</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//Sets class variables</span>
            <span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Id</span><span style="color: #339933;">=</span><span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FirstName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'LastName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOB'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Position</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Position'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Salary'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">StartDate</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'StartDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EndDate</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'EndDate'</span><span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> CreateEmployee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckVariables</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">/*** Connect to database  ***/</span>
        <span style="color: #666666; font-style: italic;">/*** Code Not Included ***/</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;INSERT INTO Employees (FirstName,LastName,DOB,Position,Salary,StartDate) VALUES ('&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">StartDate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;')&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//Inserted, and now lets return his ID number</span>
        <span style="color: #000088;">$query2</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT Id FROM Employees WHERE FirstName='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' AND LastName='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' AND DOB='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' AND StartDate='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">StartDate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>      
    <span style="color: #000000; font-weight: bold;">function</span> CheckVariables<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//makes sure we don't have any empty variables in the areas that matter</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>empty<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>empty<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>empty<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Position</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>empty<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">else</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> UpdateEmployee<span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//makes sure an ID is chosen or specified.</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">==</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">/*** Connect to database  ***/</span>
        <span style="color: #666666; font-style: italic;">/*** Code Not Included ***/</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UPDATE Employees SET <span style="color: #006699; font-weight: bold;">$field</span>='<span style="color: #006699; font-weight: bold;">$value</span>' WHERE Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> ToArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Id</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FirstName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'LastName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Position'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Position</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Salary'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOB'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'StartDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">StartDate</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'EndDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EndDate</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span>        
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here is the finished class minus a few things that you can add if you want.  What my class does is creates employees, updates specific fields, checks information, turns the info into an array, etc.  I didn&#8217;t include all the variables we listed because I am lazy, as well as the delete function.  There are always improvements that can be made, but this is a good starting block for any programmer.  So lets see how we use it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;classEmployee.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//create a new employee</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Bob&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Smith&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;01/01/99&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Position</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Data Entry&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$10</span>/hr&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$empid</span><span style="color: #339933;">=</span><span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateEmployee</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//And now he was created and entered into the system.</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$empid</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//His ID;</span>
<span style="color: #666666; font-style: italic;">//lets check to make sure he is still in the system.</span>
<span style="color: #000088;">$emp2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #000088;">$empid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$empArray</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$emp2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ToArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$empArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//ok, all looks good.  Lets update his name.</span>
<span style="color: #000088;">$emp2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">UpdateEmployee</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;FirstName&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Bobby&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$empid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Well that&#8217;s my sample.  Its pure rough draft, and probably won&#8217;t even work properly, but I am conveying the IDEA of OOP and employees.  Think how much smoother your code would be if you created a few forms asking for employees IDs and it loads it, or allows the HR Department to enter a new employees info straight into the database on a very simple form.  Good luck with this!  Let me know if there are any other problems I can help with!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/more-with-php-classes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP PDO and SQL injections</title>
		<link>http://notan00b.com/2009/08/php-pdo-and-sql-injections/</link>
		<comments>http://notan00b.com/2009/08/php-pdo-and-sql-injections/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 18:22:42 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[injections]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[MsSQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=179</guid>
		<description><![CDATA[SQL Injections o_O???]]></description>
			<content:encoded><![CDATA[<p>MySQL and MsSQL are huge when it comes to internet sites.  They are probably the easiest databases to set up and the most universal when it comes to internet apps.  The only problem is that programmers are sometimes lazy and forget to think about things like security when it comes to programming the forms and site.  When people are lazy, they leave their sites open to SQL injections.  I don&#8217;t really want to make this an SQL injection tutorial, but just want to touch on it briefly.  Lets start with a standard SQL statement that a form uses to find an Administrator password:<br />
<code>mysql&gt; SELECT * FROM Users WHERE Name='Admin' AND Pass='MyP4ssw0rd';</code><br />
Now if we add a login form and use php, we might have code structured similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$name</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT * FROM Users WHERE Name='<span style="color: #006699; font-weight: bold;">$name</span>' AND Pass='<span style="color: #006699; font-weight: bold;">$pass</span>'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This would work perfectly, and would allow people to log in.  It would also allow people to SQL inject it.  What if they typed this in:</p>
<table>
<tr>
<td>Name:</td>
<td>
<input type="text" value="admin"></td>
</tr>
<tr>
<td>Pass:</td>
<td>
<input type="text" value="admin' OR 'x'='x"></td>
</tr>
</table>
<p>
Well our SQL statement ends up looking like this:<br />
<code>SELECT * FROM Users WHERE Name='admin' AND Pass='admin' OR 'x'='x'</code><br />
&#8216;x&#8217;='x&#8217; is a TRUE statement 100% of the time, so as long as &#8216;x&#8217;='x&#8217;, it will pull up all the info you needed, and suddenly you are logged in.  This is probably the easiest SQL injection around, and does work on occasion.  There are hundreds of SQL injections, and a poorly coded site will always be susceptible.  Not only are people able to log into a site as an administrator, but they can display login info using UNION statements.<br />
One other way good programmers tend to get lazy is through their &#8220;GET&#8221; variables.  A lot of times programmers will pass variables in the URL bar: http://www.mysite.com/view.php?id=123.  There is nothing wrong with this, in fact, everyone does it and will continue to do it because it is efficient and easy to do.  The problem comes when people SQL inject that variable: view.php?id=123&#8242; and &#8216;x&#8217;='y.  This particular injection allows a hacker to test your site for susceptibility to injections in the URL bar.  If you didn&#8217;t protect your variables, your SQL statement would look like this if it wasn&#8217;t protected: <code>"SELECT * FROM Info WHERE Id='123' and 'x'='y'"</code>.  If it wasn&#8217;t protected, the hacker would see a page with NO info on it, or an error because &#8216;x&#8217; NEVER equals &#8216;y&#8217; and is a FALSE statement.  If they see a blank page or an error, they know they can continue their attack and eventually gain access to all of your information.</p>
<p>My goal is not to teach you how to hack, but rather how a simple PHP object exists and will help you avoid these types of attacks.  That object is PDO.  It comes standard with the latest releases of PHP and can be used to prevent SQL injections very simply.  PDO is a database object, that allows you to connect to a variety of different databases, send queries, and display the results.  It actually is a bit easier to code than actual mysql in PHP, but it is a complete 180 from what you have been taught using w3schools and tizag.com.  I don&#8217;t really want to get into a tutorial of PDO either because there are quite a few on the internet that explain it much better than I can right now.  I recommend checking out <a href="http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html">http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html</a> to get a grip on the basics of how PDO works.  The one thing that this tutorial does NOT explain is the &#8220;prepare&#8221; function.  He only goes into it slightly, but doesn&#8217;t describe what it does exactly.  Prepare() simply checks for all types of quotes and makes sure that no SQL injections can get through.  Here is a quick example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$mysql_host</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_user</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_pass</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_database</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;epco&quot;</span><span style="color: #339933;">;</span>
try <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mysql:host=<span style="color: #006699; font-weight: bold;">$mysql_host</span>;dbname=<span style="color: #006699; font-weight: bold;">$mysql_database</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** create the statement ***/</span>
    <span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM users WHERE user = :user AND pass = :pass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** bind the paramaters ***/</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':user'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':pass'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** execute the prepared statement ***/</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** close the database connection ***/</span>
    <span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>    
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>PDOException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>When we prepare our statement, we use a place-holder that will later assign a variable to.  When that statement is executed, all our quotes are removed or slashed.  <code>$_POST['user']="admin' OR 1=1";</code> typically becomes <code>$_POST['user']="admin\' OR 1=1";</code> and your database is protected from the attacks.</p>
<p>In conclusion, I am not advocating PDO and saying only to use that and nothing else.  I use a database class that is much smaller and does what I need it to do.  I have spoken with other programmers who have created their own class to add/strip slashes, rawurlencode/decode, and htmlspecialcharacters and connect to their databases.  PDO was created as a &#8220;universal&#8221; database object that can do whatever you want it to do with several different databases.  It is awesome and will go a long way to protect your site from SQL injections if used properly.  The prepare statement is simple, but doesn&#8217;t protect against EVERY type of attack.  Don&#8217;t be fooled into a false sense of security just because you are using a PHP object.  XSS, javascript injections, and bruteforce, attacks are all still possible even if you use this class.  Be careful in what you code, and fix any code when the holes are found by users or when you are hacked.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/php-pdo-and-sql-injections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wordpress page views hack</title>
		<link>http://notan00b.com/2009/07/wordpress-page-views-hack/</link>
		<comments>http://notan00b.com/2009/07/wordpress-page-views-hack/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 19:54:22 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[counter]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=177</guid>
		<description><![CDATA[I created this pretty quick, and it is by far, not the prettiest thing out there.  This uses an extra table in the MySQL table to keep track of pages that get viewed and how many times they are viewed.  Here is what I did:
Step 1 &#8211; Create a new table!
Go to your [...]]]></description>
			<content:encoded><![CDATA[<p>I created this pretty quick, and it is by far, not the prettiest thing out there.  This uses an extra table in the MySQL table to keep track of pages that get viewed and how many times they are viewed.  Here is what I did:</p>
<p><b>Step 1 &#8211; Create a new table!</b><br />
Go to your MySQL database and create a table called &#8220;wp_counter&#8221; with 2 fields: Post_Id and Count.  Both are Int with length 10.  Here is the SQL code you can copy and paste to make it a bit shorter:<br />
<code>CREATE TABLE `wp_counter` (`Post_Id` INT( 10 ) NOT NULL , `Count` INT( 10 ) NOT NULL) </code></p>
<p><b>Step 2 &#8211; Editing post-template.php</b><br />
This is the file that is used to display your posts (not the snippets on your front page, but full out posts).  It is located in the &#8220;wp-includes&#8221; directory.<br />
Open post-template.php for editing.<br />
Search for a function called &#8220;<code>the_content()</code>&#8220;.  It typically starts on line 165 should look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>165
166
167
168
169
170
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So what we want to do is make it so that every time it shows the content, it will update the count and display it to the user.  So we are going to change that function to look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>165
166
167
168
169
170
171
172
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	update_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span><span style="color: #0000ff;">&quot;&lt;small&gt;&lt;i&gt;Views: &quot;</span><span style="color: #339933;">.</span>get_content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/i&gt;&lt;/small&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And immediately following that, we are going to add a couple functions:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> update_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wp_counter&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post_Id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$count</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_counter'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post_Id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s it!  So your finalized post-template.php will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	update_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span><span style="color: #0000ff;">&quot;&lt;small&gt;&lt;i&gt;Views: &quot;</span><span style="color: #339933;">.</span>get_content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/i&gt;&lt;/small&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> update_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wp_counter&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post_Id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$count</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_counter'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post_Id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> get_content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now every time someone visits the page, they will see how many other people have viewed that page!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/wordpress-page-views-hack/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
