<?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>Coding Friends &#187; PHP</title>
	<atom:link href="http://www.codingfriends.com/index.php/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingfriends.com</link>
	<description>Coding Friends, place for developers.</description>
	<lastBuildDate>Sun, 04 Dec 2011 21:11:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Final and auto load a class</title>
		<link>http://www.codingfriends.com/index.php/2011/11/09/final-and-auto-load/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=final-and-auto-load</link>
		<comments>http://www.codingfriends.com/index.php/2011/11/09/final-and-auto-load/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 22:18:31 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[auto load]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[final]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1759</guid>
		<description><![CDATA[To include a class within many languages you have to define it at the top and then off you go with programming with using that class. Well within PHP you can use the __autoload function that is called when you try to create a new instance of a class. function __autoload&#40;$class_name&#41; &#123; include &#34;classes/&#34;.$class_name.&#34;.php&#34;; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>To include a class within many languages you have to define it at the top and then off you go with programming with using that class.  Well within PHP you can use the __autoload function that is called when you try to create a new instance of a class.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;classes/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$class_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>this __autoload function above takes a parameter as the class name to load and then within the code it will try and load that class with how ever you want to, in this case I have placed the classes within the directory called classes and under there classname.php filename.</p>
<p>So if you try to load the class</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$newclass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> basic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>it will look within the classes directory for the file basic.php for the autoload function above, you can alter it to load from where ever and how ever you want to.</p>
<p>The next part of this post is about the keyword &#8216;final&#8217;, the final keyword means that it is final so if you try and extend that class and extend the function that has been declared as final this will cause php interpretor to fail due to syntax error with something similar to</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Fatal error: Cannot override final method class_name::function_name<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>For an example here is two classes one is called basic and the other is called extendbasic, where the basic class has the final function within it</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> basic
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; : Hello&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	final <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayGoodbye<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; : Goodbye&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>and here is the extendclass</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> extendbasic <span style="color: #000000; font-weight: bold;">extends</span> basic
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; : the newer hello!!&quot;</span><span style="color: #339933;">;</span>	
		parent<span style="color: #339933;">::</span><span style="color: #004000;">sayHello</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: #666666; font-style: italic;">// this will cause the php engine to fail!!!!!. because it is trying to over load the function sayGoogbye which has been declared as final</span>
<span style="color: #666666; font-style: italic;">/*	public function sayGoodbye()
	{
		echo &quot;I should not get here!!&quot;;
	}*/</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here is some code to call them both which they have been placed within a directory called &#8216;classes&#8217;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;classes/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$class_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$basicClass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> basic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayHello</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayGoodbye</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> extendbasic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayHello</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayGoodbye</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and the output would be</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">basic : Hello
basic : Goodbye
extendbasic : the newer hello<span style="color: #000000; font-weight: bold;">!!</span>
extendbasic : Hello
extendbasic : Goodbye</pre></div></div>

<p>I am calling the parent function from within the extendbasic class sayHello function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/11/09/final-and-auto-load/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Curly brackets</title>
		<link>http://www.codingfriends.com/index.php/2011/03/08/curly-brackets/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=curly-brackets</link>
		<comments>http://www.codingfriends.com/index.php/2011/03/08/curly-brackets/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 22:50:52 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Curly brackets]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1564</guid>
		<description><![CDATA[It all depends on your type of coding, but I for style I do prefer to put array data within a separate part of the echo statement, for example. $arr = array&#40;&#34;first&#34; =&#62; 1, &#34;second&#34; =&#62;2&#41;; &#160; echo &#34;this is the first value &#34; . $arr&#91;&#34;first&#34;&#93;; but of course you can put the arr object [...]]]></description>
			<content:encoded><![CDATA[<p>It all depends on your type of coding, but I for style I do prefer to put array data within a separate part of the echo statement, for example.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;first&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;second&quot;</span> <span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;this is the first value &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>but of course you can put the arr object within the echo statement as long as you { .. } it out, which is kinder similar to using the &#8221; . as such,</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;this is the second value {<span style="color: #006699; font-weight: bold;">$arr</span>[&quot;</span>second<span style="color: #0000ff;">&quot;]}&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>both work, but because of the array object uses the &#8220;..&#8221; for the hash key, then you will need to use the { .. }</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/03/08/curly-brackets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CKEditor &#8211; custom dialog</title>
		<link>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-dialog/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ckeditor-custom-dialog</link>
		<comments>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-dialog/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 21:58:37 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[CKEditor]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[dialog]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1189</guid>
		<description><![CDATA[The CKEditor is a great WYSIWYG and the best thing is that you are able to customize the interface to have buttons on the toolbars, here is a way that I created a custom button with custom image attached to it. The editor is created with var editor = CKEDITOR.replace&#40; 'Content'&#41;; So from now on [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://ckeditor.com">CKEditor</a> is a great WYSIWYG and the best thing is that you are able to customize the interface to have buttons on the toolbars, here is a way that I created a custom button with custom image attached to it.</p>
<p>The editor is created with</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var editor <span style="color: #339933;">=</span> CKEDITOR.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So from now on in the variable editor is linked to the CKEditor instance, to setup the plugins to load when the CKEditor is created you call the pluginsLoaded function</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> editor.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'pluginsLoaded'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> ev <span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
           <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>CKEDITOR.<span style="color: #660066;">dialog</span>.<span style="color: #660066;">exists</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'statisticsDialog'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
                 CKEDITOR.<span style="color: #660066;">dialog</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'statisticsDialog'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'/statistics.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #006600; font-style: italic;">// Register the command used to open the dialog.</span>
           editor.<span style="color: #660066;">addCommand</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'statisticsAddCmd'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">new</span> CKEDITOR.<span style="color: #660066;">dialogCommand</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'statisticsDialog'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           editor.<span style="color: #660066;">ui</span>.<span style="color: #660066;">addButton</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'Statistics'</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#123;</span>
                        label <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Statistic'</span><span style="color: #339933;">,</span>
                        command <span style="color: #339933;">:</span> <span style="color: #3366CC;">'statisticsAddCmd'</span><span style="color: #339933;">,</span>
                        icon <span style="color: #339933;">:</span> <span style="color: #3366CC;">'/statistics_small.png'</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;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first part will check to make sure that there is not dialog already created with the same name, and if not then load the javascript file that is the custom built dialog. The second part is adding the command (the button clicked) to be linked to the custom dialog, and the third part is to add the actual button to the user interface (editor.ui).  The addButton function links to the command to bring up the custom dialog.</p>
<p>Here is the custom dialog code that will be called when the user interface button is clicked.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">CKEDITOR.<span style="color: #660066;">dialog</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'statisticsDialog'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> editor <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">// Load data asynchronously.</span>
       <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
               title <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Pick a statistic'</span><span style="color: #339933;">,</span>
               minWidth <span style="color: #339933;">:</span> <span style="color: #CC0000;">400</span><span style="color: #339933;">,</span>
               minHeight <span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span>
               onOk <span style="color: #339933;">:</span> insertOntoEditor<span style="color: #339933;">,</span>
               contents <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                       <span style="color: #009900;">&#123;</span>
                               id <span style="color: #339933;">:</span> <span style="color: #3366CC;">'tab1'</span><span style="color: #339933;">,</span>
                               label <span style="color: #339933;">:</span> <span style="color: #3366CC;">'First Tab'</span><span style="color: #339933;">,</span>
                               title <span style="color: #339933;">:</span> <span style="color: #3366CC;">'First Tab'</span><span style="color: #339933;">,</span>
                               elements <span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
                                       <span style="color: #009900;">&#123;</span>  id <span style="color: #339933;">:</span> <span style="color: #3366CC;">'graphselect'</span><span style="color: #339933;">,</span>
                                               type <span style="color: #339933;">:</span> <span style="color: #3366CC;">'select'</span><span style="color: #339933;">,</span>
                                               items <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;option1&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;link to image&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">,</span>
                               <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
                       <span style="color: #009900;">&#125;</span>
               <span style="color: #009900;">&#93;</span>
       <span style="color: #009900;">&#125;</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>The dialog, will load up a screen and have a one drop down box that will allow the user to choose from the options (will you need to insert more options, or dynamic created options if you wanted to) and once the OK button is clicked (onOK) it will call this function below</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> insertOntoEditor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
       elem <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getContentElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tab1'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'graphselect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       value <span style="color: #339933;">=</span> elem.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
               <span style="color: #003366; font-weight: bold;">var</span> writer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> CKEDITOR.<span style="color: #660066;">htmlWriter</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> fragment <span style="color: #339933;">=</span> CKEDITOR.<span style="color: #660066;">htmlParser</span>.<span style="color: #660066;">fragment</span>.<span style="color: #660066;">fromHtml</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'&lt;img src=&quot;http://'</span><span style="color: #339933;">+</span>document.<span style="color: #660066;">domain</span><span style="color: #339933;">+</span>elem.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;/&gt;'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               fragment.<span style="color: #660066;">writeHtml</span><span style="color: #009900;">&#40;</span> writer <span style="color: #009900;">&#41;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">// need to wrap up the graph image insertion into the ckeditor</span>
               CKEDITOR.<span style="color: #660066;">instances</span>.<span style="color: #660066;">Content</span>.<span style="color: #660066;">insertHtml</span><span style="color: #009900;">&#40;</span>writer.<span style="color: #660066;">getHtml</span><span style="color: #009900;">&#40;</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></pre></div></div>

<p>This will basically insert some code into the CKEditor from the drop down box, the &#8220;link to image&#8221; you will need to insert a link for the insertion.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-dialog/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CKEditor &#8211; Custom upload dialog</title>
		<link>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-upload-dialo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ckeditor-custom-upload-dialo</link>
		<comments>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-upload-dialo/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 21:39:13 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[CKEditor]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1187</guid>
		<description><![CDATA[The great WYSIWYG editor called CKEditor allows you to do a custom file upload, so that you can handle where the file is stored and also you can do your database extra inserts for example. To start with you have to tell the CKEditor where to post the file uploaded to custom built page var [...]]]></description>
			<content:encoded><![CDATA[<p>The great WYSIWYG editor called <a href="http://ckeditor.com/">CKEditor</a> allows you to do a custom file upload, so that you can handle where the file is stored and also you can do your database extra inserts for example.</p>
<p>To start with you have to tell the CKEditor where to post the file uploaded to custom built page</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">var editor = CKEDITOR.replace( 'Content',{ filebrowserUploadUrl :'/custom.imageuploader.php'});</pre></div></div>

<p>Where the custom.imageuploader.php is the actual php page that will deal with the custom page, can be done in any other language if required.  In the above code, the &#8216;Content&#8217; is the textarea to change to a CKEditor WYSIWYG.</p>
<p>Here is a basic php page that you will need to alter to store the $_FILES["upload"] into the place where you want to store and do any database code to link to the resource that you are uploading, but the bit underneath that you need to have, this will tell the CKEditor what to do after your PHP code has stored the file, the CKEditoFuncName, is required (but passed in) to tell the CKEditor what function to call after the upload has happened, the $wherestorage, is where the actual file is so that the WYSIWYG can show the image and any $message that may help the CKEditor user for any error reports.</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: #666666; font-style: italic;">// the files are stored within the upload part of the $_FILES </span>
<span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;upload&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;html&gt;
&lt;body&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
window.parent.CKEDITOR.tools.callFunction(
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;CKEditorFuncNum&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;,<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$wherestorage</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$message</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
?&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-upload-dialo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom wordpress page on a new URL</title>
		<link>http://www.codingfriends.com/index.php/2010/09/06/custom-wordpress-page-on-a-new-url/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=custom-wordpress-page-on-a-new-url</link>
		<comments>http://www.codingfriends.com/index.php/2010/09/06/custom-wordpress-page-on-a-new-url/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 20:16:36 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[action hook]]></category>
		<category><![CDATA[google search]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1170</guid>
		<description><![CDATA[I liked to have the idea of having google search my site and have it displayed within my current site design, and since wordpress allows to have action hooks that allow you to interrupt the present flow of generating the wordpress outputted page. So to have the google searched and display results within the style [...]]]></description>
			<content:encoded><![CDATA[<p>I liked to have the idea of having google search my site and have it displayed within my current site design, and since <a href="http://wordpress.org/">wordpress</a> allows to have <a href="http://codex.wordpress.org/Plugin_API/Action_Reference">action hooks</a> that allow you to interrupt the present flow of generating the wordpress outputted page.</p>
<p>So to have the google searched and display results within the style that I am using I first needed to create a plugin, if you create a file within your </p>
<p>wordpress base directory/wp-content/plugins/codingfriendsgooglesearch</p>
<p>within the file below within the that directory created above, (I saved this file as googlesearch.php, but it does not matter as long as it is a .php file with the plugin details at the top of the file between the /*&#8230; */ parts.</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: #666666; font-style: italic;">/*
Plugin Name: Google search page
Plugin URI: http://www.codingfriends.com
Donate link: http://www.codingfriends.com
Description: Google search page
Version: 0.1
Author: Ian Porter
Author URI: http://www.codingfriends.com
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> get_requested_uri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$requesturi</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</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;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$requesturi</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000088;">$requesturi</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$requesturi</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
       <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#[^/]+/#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$requesturi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">return</span> <span style="color: #000088;">$uri</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> google_search_display<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> get_requested_uri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$uri</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'googlesearch/'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span>TEMPLATEPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/googlesearch.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'template_redirect'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'google_search_display'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>What basically happens is when the template_redirect is called, this is when most of the processing of the page has already been done, and we are about to display the requested page from the blog, well in this case I would like to add function call to google_search_display, which is within this same file, and what it does is to search for &#8216;googlesearch/&#8217; within the first part of the URL requested e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">http://www.codingfriends.com/googlesearch/</pre></div></div>

<p>and if so display the googlesearch.php php file from within the templates directory, and here is my googlesearch.php file, and it displays the content within the div tag with cse-search-results, with the present style around the google search results.</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> get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;content&quot; class=&quot;narrowcolumn&quot; role=&quot;main&quot;&gt;
&lt;div id=&quot;cse-search-results&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
 var googleSearchIframeName = &quot;cse-search-results&quot;;
 var googleSearchFormName = &quot;cse-search-box&quot;;
 var googleSearchFrameWidth = 795;
 var googleSearchDomain = &quot;www.google.co.uk&quot;;
 var googleSearchPath = &quot;/cse&quot;;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://www.google.com/afsonline/show_afs_search.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</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>wordpress is really nice where you are able to alter the present execution process.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/09/06/custom-wordpress-page-on-a-new-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CS71 &#8211; Ass1 &#8211; Finance &#8211; Part 5 &#8211; View users details &#8211; buy stock &#8211; change password</title>
		<link>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-5-view-users-details-buy-stock-change-password/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cs71-ass1-finance-part-5-view-users-details-buy-stock-change-password</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-5-view-users-details-buy-stock-change-password/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:51:30 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Assignment 1]]></category>
		<category><![CDATA[CS75]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1154</guid>
		<description><![CDATA[I am doing the Harvards building dynamic websites called CS-75 (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning even if allot of it you may already know. As from the previous post, most of this page is in similar in nature [...]]]></description>
			<content:encoded><![CDATA[<p><span id="zipfile"><a href="http://www.codingfriends.com/wp-content/uploads/2010/08/cs75-ass1.zip"></a></span>I am doing the <a href="http://www.harvard.edu/">Harvards</a> building dynamic websites called <a href="http://www.cs75.net/">CS-75</a> (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  even if allot of it you may already know.</p>
<p>As from the <a href="http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-login-register-forgotten-password/">previous post</a>, most of this page is in similar in nature it is just displaying data to the user that was built up from the classes files.</p>
<p>So to buy some stock, what this page will do is wait for the user to type in a stock symbol and then use the stock class to get the data back from that symbol and then have another input that will allow the user to buy some of that stock, also if the user clicks on the link it will display at the bottom of the page new items about the stock itself.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<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;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /index.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// of course the product price may change from searching to buying, depending on the time period so need to pull back </span>
	<span style="color: #666666; font-style: italic;">// the new value, just incase.</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;buyme&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$stockID</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;STOCK&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stockAmount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;AMOUNT&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stockPurchased</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">BuyStock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stockID</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stockAmount</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;searchSymbol&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;searchSymbol&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetStocksFromYahoo</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;searchSymbol&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Buy some stock, search and buy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockPurchased</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p class=<span style="color: #000099; font-weight: bold;">\&quot;</span>details<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockPurchased</span> <span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Stock was purchased (<span style="color: #006699; font-weight: bold;">$stockID</span> amount of <span style="color: #006699; font-weight: bold;">$StockAmount</span> total price of <span style="color: #006699; font-weight: bold;">$stockPurchased</span> each price was &quot;</span><span style="color: #339933;">.</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockPurchased</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$stockAmount</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span> 
		<span style="color: #b1b100;">else</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Problem with purchasing the stock, please email the error above to the support team&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot; onsubmit=&quot;return CheckBuy()&quot;/&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</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;">$result</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;{<span style="color: #006699; font-weight: bold;">$_REQUEST</span>[&quot;</span>searchSymbol<span style="color: #0000ff;">&quot;]}&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;The price of {<span style="color: #006699; font-weight: bold;">$_REQUEST</span>[&quot;</span>searchSymbol<span style="color: #0000ff;">&quot;]} is <span style="color: #006699; font-weight: bold;">$result</span>, do you want to buy ?&lt;br/&gt;Please enter how many and tick the box.&lt;br/&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>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>AMOUNT<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>AMOUNT<span style="color: #000099; font-weight: bold;">\&quot;</span> onkeyup=<span style="color: #000099; font-weight: bold;">\&quot;</span>javascript:CheckKey(this)<span style="color: #000099; font-weight: bold;">\&quot;</span>/&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> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>STOCK<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$_REQUEST</span>[&quot;</span>searchSymbol<span style="color: #0000ff;">&quot;]}<span style="color: #000099; font-weight: bold;">\&quot;</span>/&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>checkbox<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>buyme<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>BUYME<span style="color: #000099; font-weight: bold;">\&quot;</span>/&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>submit<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span>Submit<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;&lt;b&gt;Or search for another stock&lt;/b&gt;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;Not stock of that symbol - {<span style="color: #006699; font-weight: bold;">$_REQUEST</span>[&quot;</span>searchSymbol<span style="color: #0000ff;">&quot;]}&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;br/&gt;
Search Symbol :&lt;input type=&quot;text&quot; name=&quot;searchSymbol&quot; id=&quot;searchSymbol&quot;/&gt;
&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
&lt;/form&gt;
&lt;h2&gt;Your present cash flow is&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetCash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	HTMLFooter<span style="color: #009900;">&#40;</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>To view the stock details of the user, I just display the stock that the user has from data once again from the stock class, which also includes the current price of the stock.  There is a checkbox that will allow the user to sell some of there stock (if they have any!!) and once again use the stock class to sell the stock and update the tables in the database.</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;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /index.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</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: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;remove_&quot;</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;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SellStock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;stock&quot;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$getStock</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The details of your account&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h2&gt;The stocks that the user has&lt;/h2&gt;
&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot; onsubmit=&quot;return checkSell()&quot;&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;Stock Name&lt;/td&gt;&lt;td&gt;Quantity&lt;/td&gt;&lt;td&gt;Price of Stock&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Sell&lt;/td&gt;&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$totalValue</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$usersStock</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ReturnAllStocks</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$usersStock</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$_SERVER</span>[&quot;</span>PHP_SELF<span style="color: #0000ff;">&quot;]}?stock=<span style="color: #006699; font-weight: bold;">{$theStocks[0]}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">{$theStocks[0]}</span>&lt;/a&gt;&lt;/td&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">{$theStocks[1]}</span>&lt;/td&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">{$theStocks[2]}</span>&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span>
			<span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;td&gt;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>checkbox<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$theStocks[0]}</span><span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>remove_<span style="color: #006699; font-weight: bold;">{$theStocks[0]}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$totalValue</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td colspan=<span style="color: #000099; font-weight: bold;">\&quot;</span>2<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/td&gt;&lt;td&gt;Total value&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$totalValue</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/table&gt;
&lt;input id=&quot;center&quot; type=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
&lt;/form&gt;
&lt;h2&gt;Your present cash flow is&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetCash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;Your cash + investments&lt;/h2&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetCash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$totalValue</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$getStock</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;<span style="color: #006699; font-weight: bold;">$getStock</span> more information&lt;/h2&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Date&lt;/td&gt;&lt;td&gt;Title/Link&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stockDetailsArray</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ArrayOfStockDetails</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$getStock</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockDetailsArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;{<span style="color: #006699; font-weight: bold;">$stockDetailsArray</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span><span style="color: #990000;">Date</span><span style="color: #0000ff;">&quot;]}&lt;/td&gt;&lt;td&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$stockDetailsArray</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span><span style="color: #990000;">Link</span><span style="color: #0000ff;">&quot;]}<span style="color: #000099; font-weight: bold;">\&quot;</span> target=<span style="color: #000099; font-weight: bold;">\&quot;</span>_blank<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;{<span style="color: #006699; font-weight: bold;">$stockDetailsArray</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span>Title<span style="color: #0000ff;">&quot;]}&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLFooter<span style="color: #009900;">&#40;</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>The last part is the change of the password, which just will use the user class to update the users password to the requested input from the change password page.</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;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password1&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password2&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password1&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password2&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ChangePassword</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password1&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #000088;">$notSamePassword</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /index.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Change password&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</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;">$error</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Password updated&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> 
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Cannot update the password, please contact the system admin&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notSamePassword</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Passwords are not the same&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!-- taken from http://www.html.it/articoli/nifty/index.html--&gt;
&lt;div id=&quot;login&quot;&gt;
&lt;b class=&quot;rtop&quot;&gt;
  &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; onsubmit=&quot;return CheckChangePasswords()&quot;&gt;
Change your password &lt;p&gt;
New Password : &lt;input type=&quot;password&quot; name=&quot;password1&quot; id=&quot;password1&quot; value=&quot;&quot;/&gt;&lt;/p&gt;
Retype New Password : &lt;input type=&quot;password&quot; name=&quot;password2&quot; id=&quot;password2&quot; value=&quot;&quot;/&gt;&lt;/p&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;b class=&quot;rbottom&quot;&gt;
  &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	HTMLFooter<span style="color: #009900;">&#40;</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>The actual pages that are displayed to the user are all very basic as them selves, but the actual logic and formula are all within the classes that is the gold dust as such, since it is one point of checking and also one file to update if there is a update to the yahoo etc stocks details, because would have to update the different pages that display the stocks and that is not good for testing and also updating.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-5-view-users-details-buy-stock-change-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CS71 &#8211; Ass1 &#8211; Finance &#8211; Part 4 &#8211; Login Register Forgotten password</title>
		<link>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-login-register-forgotten-password/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cs71-ass1-finance-part-2-login-register-forgotten-password</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-login-register-forgotten-password/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:41:39 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Assignment 1]]></category>
		<category><![CDATA[CS75]]></category>
		<category><![CDATA[Finance]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1151</guid>
		<description><![CDATA[I am doing the Harvards building dynamic websites called CS-75 (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning even if allot of it you may already know. Since most of the work is done in the class files, from the previous [...]]]></description>
			<content:encoded><![CDATA[<p><span id="zipfile"><a href="http://www.codingfriends.com/wp-content/uploads/2010/08/cs75-ass1.zip"></a></span>I am doing the <a href="http://www.harvard.edu/">Harvards</a> building dynamic websites called <a href="http://www.cs75.net/">CS-75</a> (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  even if allot of it you may already know.</p>
<p>Since most of the work is done in the <a href="http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-classes/">class files</a>, from the previous post then we just use the classes to only have basic php pages for the user.  So the login page is just, which also has a check for if the user is already logged in and goto the viewdetails page, or if the user requests to logout then logout the user, the main page is just logging the user in.</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;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LoginCheck</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;logout&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Logout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /viewdetails.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Login to the stocks!&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</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;">$error</span><span style="color: #339933;">==</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Not able to login, please try again&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;logout&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Thanks for using the site, you are logged out!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!-- taken from http://www.html.it/articoli/nifty/index.html--&gt;
&lt;div id=&quot;login&quot;&gt;
&lt;b class=&quot;rtop&quot;&gt;
  &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; onsubmit=&quot;&quot;&gt;
Login
&lt;p&gt;
Username : &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
&lt;/p&gt;
&lt;p&gt;
Password : &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot;/&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/p&gt;
&lt;p id=&quot;right&quot;&gt;
&lt;a href=&quot;register.php&quot;&gt;Register&lt;/a&gt; here.
&lt;/p&gt;
&lt;/form&gt;
&lt;b class=&quot;rbottom&quot;&gt;
  &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	HTMLFooter<span style="color: #009900;">&#40;</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>Here is the register page, where I send the request to the users class and utilize the return value to display either a message of check your emails (or in this case it will be a link on the top of the page) or display a error to the user depending on what could happen, e.g. not a valid valid/password(if the user turned off javascript checking) and also if there is already that email address present, the next check checks for the valid ID value that is sent to the user to validate there email.</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;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">RegisterUser</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$notValidPassword</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$notValidEmail</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$emailAddressAlreadyPresent</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$checkEmails</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;validid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckUserGUID</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;validid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$userInvalid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>			
			<span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LoginCheck</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /viewdetails.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /viewdetails.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Register&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$checkEmails</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Please check your emails to validate your email address&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notValidPassword</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Not a valid password!, please enter one that is 6 characters and has at least 1 aphla/numeric&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$emailAddressAlreadyPresent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Please use the forgotten password recovery,  already email address registered&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notValidEmail</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Not a valid email address&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userInvalid</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Does not validate correctly, please contact the system admin&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!-- taken from http://www.html.it/articoli/nifty/index.html--&gt;
&lt;div id=&quot;login&quot;&gt;
&lt;b class=&quot;rtop&quot;&gt;
  &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; onsubmit=&quot;return CheckRegister()&quot;&gt;
Register &lt;p&gt;
Username : &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
(valid email address)&lt;/p&gt;
&lt;p&gt;
Password : &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot;/&gt;
(Has to be at least 6 characters and with 1 numeric and aplha character&lt;/p&gt;
&lt;p&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;b class=&quot;rbottom&quot;&gt;
  &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	HTMLFooter<span style="color: #009900;">&#40;</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>Here is the last part, that will allow the user to enter there email to be able to get a link to enable them to change there password.</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;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ForgottenUser</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$checkEmails</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> 
			<span style="color: #000088;">$notValidEmail</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;validid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckUserGUID</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;validid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$userInvalid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>			
			<span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LoginCheck</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /changepassword.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /viewdetails.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Forgotten password&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$checkEmails</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Please check your emails to validate your email address&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notValidEmail</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Cannot find that email address&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!-- taken from http://www.html.it/articoli/nifty/index.html--&gt;
&lt;div id=&quot;login&quot;&gt;
&lt;b class=&quot;rtop&quot;&gt;
  &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; onsubmit=&quot;return CheckRegister(true)&quot;&gt;
Forgotten password, please enter your username &lt;p&gt;
Username : &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
(valid email address)&lt;/p&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;b class=&quot;rbottom&quot;&gt;
  &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	HTMLFooter<span style="color: #009900;">&#40;</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>As you can see the actual pages are really simple because most of the work is done in the class files</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-login-register-forgotten-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

