<?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>Anil Dewani</title>
	<atom:link href="http://www.anildewani.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anildewani.com</link>
	<description>Just Another Programming Blog</description>
	<lastBuildDate>Sun, 13 Nov 2011 09:10:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Bash Backup Script to backup directories and MySQL databases</title>
		<link>http://www.anildewani.com/bash-backup-script-to-backup-directories-and-mysql-databases/</link>
		<comments>http://www.anildewani.com/bash-backup-script-to-backup-directories-and-mysql-databases/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 09:51:47 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[backup script]]></category>
		<category><![CDATA[cron]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=179</guid>
		<description><![CDATA[Below is the backup script i coded and use on my server to keep backups. You should properly setup variables within the script before using it. You need to setup a cron entry to make it run as frequently as you want. I have set it to run on every sunday at 5PM using following [...]]]></description>
			<content:encoded><![CDATA[<p>Below is the backup script i coded and use on my server to keep backups. You should properly setup variables within the script before using it. You need to setup a cron entry to make it run as frequently as you want. I have set it to run on every sunday at 5PM using following cron entry.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">00 <span style="color: #000000;">17</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>anildewani<span style="color: #000000; font-weight: bold;">/</span>backup.sh <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>anildewani<span style="color: #000000; font-weight: bold;">/</span>backup.log <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></div></div>
<p>Script can make directory backups and MySQL database dumps, and store it on remote FTP location or another drive. Here goes the script:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Simple Backup Script in bash.</span><br />
<span style="color: #666666; font-style: italic;"># Coder: Anil Dewani</span><br />
<span style="color: #666666; font-style: italic;"># Date: 19 Jan 2011</span><br />
<br />
<span style="color: #666666; font-style: italic;">###################################</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Setup Vars &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</span><br />
<span style="color: #666666; font-style: italic;">###################################</span><br />
<span style="color: #666666; font-style: italic;"># Mofidy these variables according to your needs</span><br />
<span style="color: #666666; font-style: italic;"># which directory to backup</span><br />
<span style="color: #007800;">DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<br />
<span style="color: #666666; font-style: italic;"># set backup type. 0 = ftp 1 = other directory</span><br />
<span style="color: #007800;">BACKUPTYPE</span>=<span style="color: #000000;">0</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Set this if you have selected to backup data to other directory only</span><br />
<span style="color: #007800;">BACKUPDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>anildewani<span style="color: #000000; font-weight: bold;">/</span>backups<span style="color: #000000; font-weight: bold;">/</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Set following ftp details if you have selected to use ftp as backup type</span><br />
<span style="color: #666666; font-style: italic;"># ftp server</span><br />
<span style="color: #007800;">FTPSERVER</span>=ftp.domain.com<br />
<span style="color: #666666; font-style: italic;"># ftp username</span><br />
<span style="color: #007800;">FTPUSER</span>=<span style="color: #ff0000;">&quot;user@domain.com&quot;</span><br />
<span style="color: #666666; font-style: italic;"># ftp password</span><br />
<span style="color: #007800;">FTPPASS</span>=secretpassword<br />
<span style="color: #666666; font-style: italic;"># ftp remote directory</span><br />
<span style="color: #007800;">FTPDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>backups<br />
<br />
<br />
<span style="color: #666666; font-style: italic;"># Do you want to take backup of mysql databases too? 0 = false 1 = true</span><br />
<span style="color: #007800;">SQLBACKUP</span>=<span style="color: #000000;">1</span><br />
<span style="color: #666666; font-style: italic;"># if yes, setup following details</span><br />
<span style="color: #666666; font-style: italic;"># MySQL username</span><br />
<span style="color: #007800;">SQLUSER</span>=root<br />
<span style="color: #666666; font-style: italic;"># MySQL password</span><br />
<span style="color: #007800;">SQLPASS</span>=secretpassword<br />
<span style="color: #666666; font-style: italic;"># MySQL databases to include in backup. Seperate each database name with a comma (,)</span><br />
<span style="color: #007800;">SQLDBS</span>=mysql,userdata,admindata<br />
<br />
<br />
<br />
<span style="color: #666666; font-style: italic;">##################################</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; Do Not Edit Below &nbsp; &nbsp; &nbsp; &nbsp;#</span><br />
<span style="color: #666666; font-style: italic;">##################################</span><br />
<br />
<span style="color: #007800;">DIRBACKUPFILE</span>=dirbackup.<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>d-<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">`</span>.tgz<br />
<span style="color: #007800;">SQLBACKUPFILE</span>=sqlbackup.<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>d-<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">`</span>.tgz<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$DIR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Directory to backup does not exist. Directory backup aborted. &lt;br /&gt;&quot;</span><br />
<span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#do here</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zcvf</span> <span style="color: #007800;">$DIRBACKUPFILE</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DIR</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$BACKUPTYPE</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ncftpput <span style="color: #660033;">-u</span> <span style="color: #007800;">$FTPUSER</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$FTPPASS</span> <span style="color: #007800;">$FTPSERVER</span> <span style="color: #007800;">$FTPDIR</span> <span style="color: #007800;">$DIRBACKUPFILE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Directory backup file uploaded to FTP Server&lt;br /&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$BACKUPTYPE</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$BACKUPDIR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup Directory does not exist. Creating it right now.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$BACKUPDIR</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$DIRBACKUPFILE</span> <span style="color: #007800;">$BACKUPDIR</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Directory backup file moved to backup directory&lt;br /&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup type was not set properly&lt;br /&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$SQLBACKUP</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#code to create sql files</span><br />
&nbsp; &nbsp; <span style="color: #007800;">arr</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$SQLDBS</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$arr</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mysqldump -u<span style="color: #007800;">$SQLUSER</span> -p<span style="color: #007800;">$SQLPASS</span> <span style="color: #660033;">--opt</span> <span style="color: #007800;">$x</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$x</span>.sql<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">done</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#code to make tarball of those sql files</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zcvf</span> <span style="color: #007800;">$SQLBACKUPFILE</span> <span style="color: #000000; font-weight: bold;">*</span>.sql<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$arr</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$x</span>.sql<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">done</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$BACKUPTYPE</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ncftpput <span style="color: #660033;">-u</span> <span style="color: #007800;">$FTPUSER</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$FTPPASS</span> <span style="color: #007800;">$FTPSERVER</span> <span style="color: #007800;">$FTPDIR</span> <span style="color: #007800;">$SQLBACKUPFILE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;SQL backup file uploaded to FTP Server&lt;br /&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$BACKUPTYPE</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$BACKUPDIR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup Directory does not exist. Creating it right now.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$BACKUPDIR</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$SQLBACKUPFILE</span> <span style="color: #007800;">$BACKUPDIR</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;SQL backup file moved to backup directory&lt;br /&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup type was not set properly&lt;br /&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #666666; font-style: italic;">#exit, bye bye!</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/bash-backup-script-to-backup-directories-and-mysql-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pastebin.com Bash Script &#8211; Paste directly from your terminal</title>
		<link>http://www.anildewani.com/pastebin-com-bash-script-paste-directly-from-your-terminal/</link>
		<comments>http://www.anildewani.com/pastebin-com-bash-script-paste-directly-from-your-terminal/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 15:27:23 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[pastebin]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=168</guid>
		<description><![CDATA[Pastebin.com is one of well-known code paste sites around the globe. Programmers mostly use such sites to share code between other programmers or while chatting on IRC to solve some problems. I have developed a bash script which can easily take input from stdin and just throw back pastebin.com url. Forget about copying the code, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" src="http://vavai.net/wp-content/uploads/2010/01/bash-script.png" alt="" height="100" width="100"/>Pastebin.com is one of well-known code paste sites around the globe. Programmers mostly use such sites to share code between other programmers or while chatting on IRC to solve some problems. I have developed a bash script which can easily take input from stdin and just throw back pastebin.com url. Forget about copying the code, pasting it again to the site. Below is how you can use the script and the source. </p>
<p>Usage:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#pass stdin using | operator</span><br />
<span style="color: #666666;">anil@ubuntu:~$ </span><span style="color: #c20cb9; font-weight: bold;">cat</span> bashcode.txt <span style="color: #000000; font-weight: bold;">|</span> .<span style="color: #000000; font-weight: bold;">/</span>pastebin <span style="color: #660033;">-t</span> <span style="color: #c20cb9; font-weight: bold;">bash</span><br />
http:<span style="color: #000000; font-weight: bold;">//</span>pastebin.com<span style="color: #000000; font-weight: bold;">/</span>93SuECwJ<br />
<br />
<span style="color: #666666; font-style: italic;">#or you can just use command as below, paste code and then press ctrl + D to get the link</span><br />
<span style="color: #666666;">anil@ubuntu:~$ </span>.<span style="color: #000000; font-weight: bold;">/</span>pastebin <span style="color: #660033;">-n</span> anil <span style="color: #660033;">-t</span> php<br />
<span style="color: #000000; font-weight: bold;">&lt;</span>?php<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Hey, this is a test&quot;</span>;<br />
?<span style="color: #000000; font-weight: bold;">&gt;</span><br />
http:<span style="color: #000000; font-weight: bold;">//</span>pastebin.com<span style="color: #000000; font-weight: bold;">/</span>ixPbWfS9</div></div>
<p>Source:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #666666; font-style: italic;"># Paste at Pastebin.com using command line (browsers are slow, right?)</span><br />
<span style="color: #666666; font-style: italic;"># coder : Anil Dewani</span><br />
<span style="color: #666666; font-style: italic;"># date : Novemeber 7, 2010</span><br />
<br />
<span style="color: #666666; font-style: italic;">#help function</span><br />
howto<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\<br />
</span> &nbsp; &nbsp;Pastebin.com Bash Script <span style="color: #000099; font-weight: bold;">\<br />
</span> &nbsp; <br />
&nbsp; &nbsp; Usage : $0 [ -n &lt;paste name&gt; ] [ -e &lt;paste email&gt; ] [ -t &lt;type of code&gt; ] [ -h ]<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; &lt;paste name&gt; &nbsp; Specify the name of paste to be used (optional)<br />
&nbsp; &nbsp; &lt;paste email&gt; &nbsp;Specify email to be used while pasting (optional)<br />
&nbsp; &nbsp; &lt;type of code&gt; Specify code language used, use any of the following values (optional and default value is plain text)<br />
<br />
&nbsp; &nbsp; =&gt; Some famous [ -t &lt;type of code&gt; ] Values::<br />
<br />
&nbsp; &nbsp; php - PHP<br />
&nbsp; &nbsp; actionscript3 - Action Script 3<br />
&nbsp; &nbsp; asp - ASP<br />
&nbsp; &nbsp; bash - BASH script<br />
&nbsp; &nbsp; c - C language<br />
&nbsp; &nbsp; csharp - C#<br />
&nbsp; &nbsp; cpp - C++ <br />
&nbsp; &nbsp; java - JAVA<br />
&nbsp; &nbsp; sql - SQL <br />
&nbsp; &nbsp; &quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<br />
<span style="color: #007800;">NAME</span>=<br />
<span style="color: #007800;">EMAIL</span>=<br />
<span style="color: #007800;">TYPE</span>=<br />
<br />
<span style="color: #666666; font-style: italic;">#getopts, config</span><br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">getopts</span> <span style="color: #ff0000;">&quot;n:e:t:h&quot;</span> OPTION<br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$OPTION</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; n<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">NAME</span>=<span style="color: #007800;">$OPTARG</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; e<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">EMAIL</span>=<span style="color: #007800;">$OPTARG</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; t<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">TYPE</span>=<span style="color: #007800;">$OPTARG</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; h<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; howto<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; ?<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; howto<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">esac</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #666666; font-style: italic;">#get data from stdin</span><br />
<span style="color: #007800;">INPUT</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(&lt;/dev/stdin)</span>&quot;</span><br />
<br />
<span style="color: #007800;">querystring</span>=<span style="color: #ff0000;">&quot;paste_private=0&amp;paste_code=<span style="color: #007800;">${INPUT}</span>&amp;paste_name=<span style="color: #007800;">${NAME}</span>&amp;paste_email=<span style="color: #007800;">${EMAIL}</span>&amp;paste_format=<span style="color: #007800;">${TYPE}</span>&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;">#post data to pastebin.com API</span><br />
curl <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${querystring}</span>&quot;</span> http:<span style="color: #000000; font-weight: bold;">//</span>pastebin.com<span style="color: #000000; font-weight: bold;">/</span>api_public.php<br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/pastebin-com-bash-script-paste-directly-from-your-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You Know You’re An Internet Marketer When</title>
		<link>http://www.anildewani.com/you-know-you%e2%80%99re-an-internet-marketer-when/</link>
		<comments>http://www.anildewani.com/you-know-you%e2%80%99re-an-internet-marketer-when/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 19:23:38 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[Internet Marketing]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=186</guid>
		<description><![CDATA[1). You send your kids their allowance by Paypal. 2). Your Mom asks you to email her your children’s Christmas gift wishlist and you embed it with affiliate links. 3). You check domain name availability before naming your kids. 4). You go to work in your underwear. 5). You have trouble explaining to your friends [...]]]></description>
			<content:encoded><![CDATA[<p>1). You send your kids their allowance by Paypal.<br />
2). Your Mom asks you to email her your children’s Christmas gift wishlist and you embed it with affiliate links.<br />
3). You check domain name availability before naming your kids.<br />
4). You go to work in your underwear.<br />
5). You have trouble explaining to your friends what “you do.”<br />
6). Everybody else is looking for a job and you’re trying to get rid of yours<br />
7). The neighbours think you’re into something illegal when they observe you not going to work but having all the trappings of success.<br />
8). Every item at your garage sale ends with a ‘7.’<br />
9). You add three ps’s to an email to your mother.<br />
10). Your wife accuse you to be cheating on her with Alexa.<br />
11). You make a lot of money spending max 1 hour per day in front of your PC.<br />
12). You do your work in the toilet<br />
13). You wake up on midnight and then your body opens PayPal automatically like a bots, ignoring your wife’s bulging eyes<br />
14). When you announce the birth of your child as a &#8220;New Product Launch&#8221;<br />
15). When you are worried more getting banned from your cpa network than getting caught cheating on your girlfriend.<br />
16). When you&#8217;ve thought about different ways to monetize Justin Bieber and tried at least one.<br />
17). when you take a post like this and bundle it up into a nice little pdf file and throw it up for sale at DP.<br />
18). You would prefer freezing yourself instead of your PayPal account<br />
19). when you parents and other older people you know think that you are going to go to jail someday<br />
20). When 80% of your electric bill goes to all the computers you have on autopilot in your bedroom!<br />
21). when you wake up early on the morning just to see everyone else go to work (have a big grin) and then make a cup of coffee, turn on your computer and check how much you made last night!<br />
22). Christmas is coming up and you tell your friends and family, &#8220;No, I don&#8217;t want a shirt, a tie, or the Xbox 360. What do you want then? I want Scrapebox, Xrumer, oh, and Sitegrinder too&#8230;&#8221;<br />
And they&#8217;re like&#8230;&#8221;WTF is a Scrapebox and a Sitegrinder? And Xrumer sounds like some porn shit&#8230;&#8221;<br />
23). When you don&#8217;t tell people you&#8217;re an &#8220;internet marketer&#8221;. Web developer sounds so much better.<br />
24). when you start leaving 100% tips on the table<br />
25). When you hire high school nerds to write articles for you in exchange of alcohal.<br />
26). When people view you with suspicion thinking you send all those Nigerian spam emails.<br />
27). When waking up before 11 am feels like an achievement<br />
28). When you go to a new store and ask for a review copy<br />
29). you press your finger on an underlined word in a printed book<br />
30). Your the only one out of your friends who&#8217;s making $$$ on facebook instead of spending $$$> on farmville cash </p>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/you-know-you%e2%80%99re-an-internet-marketer-when/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing SSH Server on Windows 2008</title>
		<link>http://www.anildewani.com/installing-ssh-server-on-windows-2008-r2/</link>
		<comments>http://www.anildewani.com/installing-ssh-server-on-windows-2008-r2/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 07:02:58 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=150</guid>
		<description><![CDATA[Installing an SSH server on the windows server will help you manage your server by remotely accessing the server terminal. It helps you control the server when you don&#8217;t have GUI access. All you need is an SSH client (such as puTTY), which helps you develop connection to the server in an encrypted manner. There [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" src="http://www.maximumpc.com/files/u4965/Windows_Server_2008_R2.jpg" alt="windows server 2008 r2" width="200" height="180" />Installing an SSH server on the windows server will help you manage your server by remotely accessing the server terminal. It helps you control the server when you don&#8217;t have GUI access. All you need is an SSH client (such as puTTY), which helps you develop connection to the server in an encrypted manner.</p>
<p>There are many SSH server options available for windows 2008, some of them are as follows:</p>
<ul>
<li>SSH.com – Free non-commercial SSH Server</li>
<li>SSH.com – SSH Tectia Client and Server (commercial)</li>
<li>OpenSSH</li>
<li>Van Dyke – vShell 3.0 Server (commercial)</li>
<li>Free SSHd (<strong>this is what we are gonna use in this tutorial</strong>)</li>
<li>WinSSHd (commercial)</li>
<li>Kpym Telnet/SSH Server</li>
<li>copSSH for Windows (a modified build of OpenSSH)</li>
<li>Sysax Multi-Server (SSH Server) for Windows</li>
</ul>
<p>We are gonna use Free SSHd in this tutorial, its easiest to install and works perfectly. Visit there official site and download the .exe file from the <a href="http://www.freesshd.com/?ctt=download">Downloads page</a>. After download is over, run the exe file..<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/08/1setup.jpg" alt="freesshd setup" /></p>
<p>Keep pressing next and install it on your server, at the last step you will be asked about creating private keys, press Yes.<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/08/2privatekey.jpg" alt="private key freesshd" /></p>
<p>Click yes to run FreeSSHd as a system service.<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/08/3service.jpg" alt="system service FreeSSHd" /></p>
<p>FreeSSHd will now be running on your server, the next job is to add an user. To do so, click on FreeSSHd icon at bottom right icon tray. That shall open settings, click on &#8220;users&#8221; tab and click &#8220;add&#8221; to add an new user.<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/08/4adduser.jpg" alt="add user freesshd" /></p>
<p>Add details as showed in the image above. There are many other options you can make use of, but i&#8217;m pretty sure you can do that well by own <img src='http://www.anildewani.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>That being done, It is necessary to add an exception to the windows firewall to allow connections from TCP port 22. Thus, click on &#8220;windows firewall and advanced security&#8221; option from &#8220;Administrative tools&#8221; in start menu.<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/08/5firewall.jpg" alt="adminstrative and firewall windows" /></p>
<p>Click on &#8220;Inbound Rules&#8221; on the left, and after that click on &#8220;New Rule&#8221; from the right part of window.<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/08/6addrule.jpg" alt="add rule" width="700" /></p>
<p>That shall give you a new window. Click on &#8220;port&#8221; and press Next.<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/08/7port.jpg" alt="port firewall 22" /></p>
<p>Select TCP and write &#8220;22&#8243; in Specific local ports option. That shall allow connections from port 22.<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/08/8tcp22.jpg" alt="22 port tcp allow" /></p>
<p>Keep on pressing Next until Finish.<br />
That&#8217;s it. you have set up an SSH server. Now you can use any SSH client (for example, puTTY) and access the server terminal via SSH (tcp port 22).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/installing-ssh-server-on-windows-2008-r2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating user friendly interface with dialog command</title>
		<link>http://www.anildewani.com/creating-user-friendly-interface-with-dialog-command/</link>
		<comments>http://www.anildewani.com/creating-user-friendly-interface-with-dialog-command/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 19:15:41 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=127</guid>
		<description><![CDATA[In this article, we will see how to use &#8220;dialog&#8221; command to create a user-friendly interface for your bash scripts. dialog command helps us build text-based front-end windows. Still confused about what i am talking about exactly? The below image makes it all clear. We are gonna learn how to make such windows (there are [...]]]></description>
			<content:encoded><![CDATA[<p>In this article, we will see how to use &#8220;dialog&#8221; command to create a user-friendly interface for your bash scripts. dialog command helps us build text-based front-end windows. Still confused about what i am talking about exactly? The below image makes it all clear. We are gonna learn how to make such windows (there are various kinds of them).<br />
<a href="http://www.anildewani.com/wp-content/uploads/2010/06/dialogsunix1.jpg"><img src="http://www.anildewani.com/wp-content/uploads/2010/06/dialogsunix1.jpg" alt="" title="dialogsunix1" width="458" height="226" class="aligncenter size-full wp-image-128" /></a><br />
I am gonna show you how to create such windows and how to integrate them into your bash script. Following are various different types of dialog box:</p>
<ul>>> calendar, checklist, form, fselect, gauge, infobox, inputbox, inputmenu, menu, msgbox, password, pause, radiolist, tailbox, tailboxbg, textbox, timebox, and yesno.
</ul>
<p>we are gonna cover some of the basic one&#8217;s.<br />
Tip Tip : Mostly the random numbers which you see behind an dialog command are nothing but height and width. heh. <img src='http://www.anildewani.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
<strong>msgbox</strong><br />
The image at top of this post is an pure example of an &#8220;message box&#8221;</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">dialog</span> <span style="color: #660033;">--title</span> <span style="color: #ff0000;">&quot;This is a message box title&quot;</span> \<br />
<span style="color: #660033;">--msgbox</span> <span style="color: #ff0000;">&quot;Hello, this is the message box text.&quot;</span> <span style="color: #000000;">10</span> <span style="color: #000000;">30</span></div></div>
<p><strong>yesno</strong></p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">dialog</span> <span style="color: #660033;">--title</span> <span style="color: #ff0000;">&quot;www.anildewani.com&quot;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">--yesno</span> <span style="color: #ff0000;">&quot;Are you gonna press yes or not ?&quot;</span> <span style="color: #000000;">5</span> <span style="color: #000000;">40</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">in</span><br />
<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Yes! You pressed Yes&quot;</span><span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No! You pressed No&quot;</span><span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000;">255</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Esc? Thats cool with me&quot;</span><span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span></div></div>
<p>That would look something like :<br />
<a href="http://www.anildewani.com/wp-content/uploads/2010/06/yesnodialog.jpg"><img src="http://www.anildewani.com/wp-content/uploads/2010/06/yesnodialog.jpg" alt="" title="yesnodialog" width="603" height="198" class="aligncenter size-full wp-image-134" /></a></p>
<p><strong>Inputbox</strong><br />
Inputbox option is used to read input from user. It mostly prints out instantly upon submission to the stderr. Following is an sample bash script which probably redirects the stderr to an temp file and store the input.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">dialog</span> <span style="color: #660033;">--title</span> <span style="color: #ff0000;">&quot;www.anildewani.com&quot;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">--inputbox</span> <span style="color: #ff0000;">&quot;Enter your name...&quot;</span> <span style="color: #000000;">10</span> <span style="color: #000000;">40</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">dialog</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">in</span><br />
<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Welcome <span style="color: #780078;">`cat /tmp/dialog`</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Cancel was pressed&quot;</span><span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span></div></div>
<p>That&#8217;s how it shall look like:<br />
<a href="http://www.anildewani.com/wp-content/uploads/2010/06/inputboxdialog.jpg"><img src="http://www.anildewani.com/wp-content/uploads/2010/06/inputboxdialog.jpg" alt="" title="inputboxdialog" width="453" height="230" class="aligncenter size-full wp-image-137" /></a></p>
<p><strong>Textbox</strong><br />
Textbox option is used to show contents of an file into an window. User can even scroll through and use various keys like pageup and pagedown. User can even search by pressing /</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">dialog</span> <span style="color: #660033;">--title</span> <span style="color: #ff0000;">&quot;www.anildewani.com&quot;</span> \<br />
&nbsp;<span style="color: #660033;">--textbox</span> file.txt <span style="color: #000000;">20</span> <span style="color: #000000;">50</span></div></div>
<p>It will display contents of file.txt in following manner:<br />
<a href="http://www.anildewani.com/wp-content/uploads/2010/06/textboxdialog.jpg"><img src="http://www.anildewani.com/wp-content/uploads/2010/06/textboxdialog.jpg" alt="" title="textboxdialog" width="470" height="362" class="aligncenter size-full wp-image-139" /></a></p>
<p><strong>Checklist</strong></p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">dialog</span> <span style="color: #660033;">--title</span> <span style="color: #ff0000;">&quot;www.anildewani.com&quot;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">--checklist</span> <span style="color: #ff0000;">&quot;Select the OS you use..&quot;</span> <span style="color: #000000;">20</span> <span style="color: #000000;">40</span> <span style="color: #000000;">3</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;CentOS&quot;</span> <span style="color: #ff0000;">&quot;&quot;</span> on \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;Ubuntu&quot;</span> <span style="color: #ff0000;">&quot;&quot;</span> off \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;Fedora&quot;</span> <span style="color: #ff0000;">&quot;&quot;</span> off <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">dialog</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">in</span><br />
<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Glad to know you use <span style="color: #780078;">`cat /tmp/dialog`</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Cancel was pressed&quot;</span><span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span></div></div>
<p>In above example, 20 is height, 40 is the width and 3 is total number of choices.<br />
Below is image of how this should look like:<br />
<a href="http://www.anildewani.com/wp-content/uploads/2010/06/checklistdialog.jpg"><img src="http://www.anildewani.com/wp-content/uploads/2010/06/checklistdialog.jpg" alt="" title="checklistdialog" width="415" height="368" class="aligncenter size-full wp-image-141" /></a></p>
<p><strong>Radiolist</strong><br />
Just replace &#8211;checklist in checklist example script to &#8211;radiolist. Rest is all the same <img src='http://www.anildewani.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Guage</strong><br />
Guage window can be used to show a progress bar showing the progress of your program. Lets look at an simple example.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>..<span style="color: #000000;">100</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span>;<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">dialog</span> <span style="color: #660033;">--guage</span> <span style="color: #ff0000;">&quot;Loading www.anildewani.com ...&quot;</span> <span style="color: #000000;">7</span> <span style="color: #000000;">70</span> <span style="color: #000000;">0</span></div></div>
<p>The dialog commands gets input from code between parenthesis. That&#8217;s the tricky part. <img src='http://www.anildewani.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
Here&#8217;s the screenshot of how it looks like:<br />
<a href="http://www.anildewani.com/wp-content/uploads/2010/06/guagedialog.jpg"><img src="http://www.anildewani.com/wp-content/uploads/2010/06/guagedialog.jpg" alt="" title="guagedialog" width="651" height="159" class="aligncenter size-full wp-image-143" /></a></p>
<p>Will update with more when time allows me <img src='http://www.anildewani.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/creating-user-friendly-interface-with-dialog-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Counter Strike 1.6 No-Steam Linux Server</title>
		<link>http://www.anildewani.com/creating-a-counter-strike-1-6-no-steam-linux-se/</link>
		<comments>http://www.anildewani.com/creating-a-counter-strike-1-6-no-steam-linux-se/#comments</comments>
		<pubDate>Sun, 23 May 2010 12:12:49 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[counter strike]]></category>
		<category><![CDATA[cs 1.6]]></category>
		<category><![CDATA[cs 1.6 server]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[hlds]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=114</guid>
		<description><![CDATA[Creating a personal server for your clan or group of friends is always good. you get to play what you want. In this tutorial i am gonna explain how to create a Counter strike 1.6 Nosteam linux server. Make sure to have around 1-2GB free disk space and an speedy internet connection. First of all, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.instructables.com/image/FVMEL4ZFFFIVKET/HLDS-Counter-Strike-16-Server.jpg" alt="cs 1.6" width="200" height="200" align="right" />Creating a personal server for your clan or group of friends is always good. you get to play what you want. In this tutorial i am gonna explain how to create a Counter strike 1.6 Nosteam linux server. Make sure to have around 1-2GB free disk space and an speedy internet connection. First of all, let&#8217;s create a separate directory. we call it hlds.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> hlds<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> hlds</div></div>
<p>Next step would be to download all the essential&#8217;s we gonna need. Fire following commands.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.steampowered.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>hldsupdatetool.bin<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.linuxcumsa.ro<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>engine.v15.tgz<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>ovh.dl.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>sourceforge<span style="color: #000000; font-weight: bold;">/</span>halflifeadmin<span style="color: #000000; font-weight: bold;">/</span>halflife-admin-2.50.60-linux.tar.gz</div></div>
<p>First one is the hldsupdatetool, second download is the patch and the last one is &#8220;adminmod + metamod&#8221; </p>
<p><strong>Setting up the server</strong><br />
1. executing hldsupdatetool.bin</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x hldsupdatetool.bin <br />
.<span style="color: #000000; font-weight: bold;">/</span>hldsupdatetool.bin</div></div>
<p>This shall show you agreement, just type yes and press enter. It will extract a new file named &#8220;steam&#8221;.</p>
<p>2. updating and downloading game data. execute following command</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>steam <span style="color: #660033;">-command</span> update <span style="color: #660033;">-game</span> valve <span style="color: #660033;">-dir</span> .</div></div>
<p>Repeat the same command again. It shall download the game data.</p>
<p>3. Downloading and installing cstrike mod.. execute the following command just once</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>steam <span style="color: #660033;">-command</span> update <span style="color: #660033;">-game</span> cstrike <span style="color: #660033;">-dir</span> .</div></div>
<p>Now, the data is up to date. </p>
<p>4. Patching. Execute the following command and it will patch the server to allow no-steam clients to connect.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> engine_amd.so <br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> engine_i486.so <br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> engine_i686.so <br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> xfvz engine.v15.tgz</div></div>
<p>5. Changing server.cfg<br />
Move to /hlds/cstrike directory and delete server.cfg and create server.cfg again in same directory with following data.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">hostname</span> <span style="color: #ff0000;">&quot;Server Name&quot;</span><br />
mp_autokick <span style="color: #000000;">0</span><br />
mp_autocrosshair <span style="color: #000000;">0</span><br />
mp_autoteambalance <span style="color: #000000;">0</span><br />
mp_buytime <span style="color: #000000;">2</span><br />
mp_consistency <span style="color: #000000;">1</span><br />
mp_c4timer <span style="color: #000000;">35</span><br />
mp_fadetoblack <span style="color: #000000;">0</span><br />
mp_falldamage <span style="color: #000000;">0</span><br />
mp_flashlight <span style="color: #000000;">1</span><br />
mp_forcecamera <span style="color: #000000;">3</span><br />
mp_forcechasecam <span style="color: #000000;">2</span><br />
mp_friendlyfire <span style="color: #000000;">1</span><br />
mp_freezetime <span style="color: #000000;">0</span><br />
mp_fraglimit <span style="color: #000000;">0</span><br />
mp_hostagepenalty <span style="color: #000000;">0</span><br />
mp_limitteams <span style="color: #000000;">6</span><br />
mp_logfile <span style="color: #000000;">1</span><br />
mp_logmessages <span style="color: #000000;">1</span><br />
mp_logdetail <span style="color: #000000;">3</span><br />
mp_maxrounds <span style="color: #000000;">0</span><br />
mp_playerid <span style="color: #000000;">0</span><br />
mp_roundtime <span style="color: #000000;">3</span><br />
mp_startmoney <span style="color: #000000;">16000</span><br />
mp_timelimit <span style="color: #000000;">0</span><br />
mp_tkpunish <span style="color: #000000;">0</span><br />
mp_winlimit <span style="color: #000000;">0</span><br />
sv_aim <span style="color: #000000;">0</span><br />
sv_airaccelerate <span style="color: #000000;">10</span><br />
sv_airmove <span style="color: #000000;">1</span><br />
sv_allowdownload <span style="color: #000000;">1</span><br />
sv_clienttrace <span style="color: #000000;">1.0</span><br />
sv_clipmode <span style="color: #000000;">0</span><br />
sv_allowupload <span style="color: #000000;">1</span><br />
sv_cheats <span style="color: #000000;">0</span><br />
sv_gravity <span style="color: #000000;">800</span><br />
sv_lan <span style="color: #000000;">1</span><br />
sv_maxrate <span style="color: #000000;">7000</span><br />
sv_maxspeed <span style="color: #000000;">320</span><br />
sv_maxupdaterate <span style="color: #000000;">101</span><br />
sys_ticrate <span style="color: #000000;">10000</span><br />
decalfrequency <span style="color: #000000;">60</span><br />
pausable <span style="color: #000000;">0</span><br />
log on<br />
decalfrequency <span style="color: #000000;">60</span><br />
edgefriction <span style="color: #000000;">2</span><br />
host_framerate <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">exec</span> listip.cfg<br />
<span style="color: #7a0874; font-weight: bold;">exec</span> banned.cfg<br />
rcon_password PASSWORD</div></div>
<p>Please don&#8217;t forget to edit &#8220;server name&#8221; with your own server name which you desire and PASSWORD with the password you want to set.</p>
<p>6. Setting up adminmod and metamod</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">tar</span> xfvz halflife-admin-2.50.60-linux.tar.gz</div></div>
<p>Install adminmod</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> Adminmod <br />
.<span style="color: #000000; font-weight: bold;">/</span>install_admin</div></div>
<p>Follow the instructions and install it.</p>
<p>7. Configuring adminmod</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>hlds<span style="color: #000000; font-weight: bold;">/</span>cstrike<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>adminmod<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">nano</span> adminmod.cfg</div></div>
<p>Change allow_client_exec to 1.<br />
Save and close.</p>
<p>8. Adding admin</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">nano</span> users.ini</div></div>
<p>add following line to the end of the file</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">yourusername:yourpassword:<span style="color: #000000;">131071</span></div></div>
<p>Replace it with your own username and password which you desire.</p>
<p>9. Go in /hlds/cstrike directory and open liblist.gam with pico, nano or mcedit. Replace secure &#8220;1&#8243; with secure &#8220;0&#8243;. </p>
<p>10. Starting the server</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>hlds_run <span style="color: #660033;">-game</span> cstrike &nbsp;+sv_lan <span style="color: #000000;">1</span> <span style="color: #660033;">-nomaster</span> +maxplayers <span style="color: #000000;">18</span> +map de_dust2</div></div>
<p>If you get any error related to libSteamValidateUserIDTickets_i386.so..</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Error:Error:libSteamValidateUserIDTickets_i386.so: cannot open shared object file: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory</div></div>
<p>than go at following url and download libSteamValidateUserIDTickets_i386.so and place it in /hlds directory.</p>
<p>http://amxx.pl/post-a1559-libsteamvalidateuseridtickets-i386rar.html</p>
<p>Or else if you get any error related to metamod_i386.so file.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">LoadLibrary failed on <span style="color: #000000; font-weight: bold;">/</span>hlds<span style="color: #000000; font-weight: bold;">/</span>cstrike<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>metamod<span style="color: #000000; font-weight: bold;">/</span>dlls<span style="color: #000000; font-weight: bold;">/</span>metamod_i386.so: <span style="color: #000000; font-weight: bold;">/</span>hlds<span style="color: #000000; font-weight: bold;">/</span>cstrike<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>metamod<span style="color: #000000; font-weight: bold;">/</span>dlls<span style="color: #000000; font-weight: bold;">/</span>metamod_i386.so: cannot open shared object file: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory</div></div>
<p>Download the file using following command and try again</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>hlds<span style="color: #000000; font-weight: bold;">/</span>cstrike<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>metamod<span style="color: #000000; font-weight: bold;">/</span>dlls<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>prdownloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>metamod<span style="color: #000000; font-weight: bold;">/</span>metamod-<span style="color: #000000;">1.19</span>-linux.tar.gz?download<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> xfvz metamod-<span style="color: #000000;">1.19</span>-linux.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> metamod-<span style="color: #000000;">1.19</span>-linux.tar.gz</div></div>
<p>Go play Go! ;D</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/creating-a-counter-strike-1-6-no-steam-linux-se/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building an Login System in PHP</title>
		<link>http://www.anildewani.com/building-an-login-system-in-php/</link>
		<comments>http://www.anildewani.com/building-an-login-system-in-php/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 13:06:36 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[session_start]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=97</guid>
		<description><![CDATA[We will see how a simple login system can be build using php. First of all, we must create a database with any random name you like and fire the following SQL query to create a table &#8216;userpass&#8217; with fields &#8216;id&#8217;,'username&#8217; and &#8216;password&#8217;. CREATE TABLE IF NOT EXISTS `userpass` &#40; `id` INT&#40;4&#41; NOT NULL AUTO_INCREMENT, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.anildewani.com/downloads/loginsystem.rar"><img class="alignright" src="http://www.anildewani.com/wp-content/uploads/2010/04/source.jpg" alt="Get Source" /></a>We will see how a simple login system can be build using php. First of all, we must create a database with any random name you like and fire the following SQL query to create a table &#8216;userpass&#8217; with fields &#8216;id&#8217;,'username&#8217; and &#8216;password&#8217;.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`userpass`</span> <span style="color: #66cc66;">&#40;</span><br />
<span style="color: #ff0000;">`id`</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span><br />
<span style="color: #ff0000;">`username`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">65</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span><br />
<span style="color: #ff0000;">`password`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">65</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span><br />
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM &nbsp;<span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>latin1;</div></div>
<p>After getting ready with the database, our first step is to create a registration form. Following is the source of register.php. It&#8217;s an simple form. I make use of external style-sheets to make it look better, you can download the whole source by clicking on the icon above.</p>
<p><strong>register.php</strong><br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/04/register.jpg" alt="Registration form" /></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;html&gt;<br />
&lt;head&gt;<br />
&nbsp; &nbsp; &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; type=&quot;text/css&quot; charset=&quot;utf-8&quot;&gt;<br />
&nbsp; &nbsp; &lt;link rel=&quot;stylesheet&quot; href=&quot;style2.css&quot; type=&quot;text/css&quot; charset=&quot;utf-8&quot;&gt;<br />
&nbsp; &nbsp; &lt;title&gt;Register&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id=&quot;main&quot;&gt;<br />
&nbsp; &nbsp; &lt;div id=&quot;top&quot;&gt;&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div id=&quot;middle&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;h1&gt;Registration Form&lt;/h1&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;error&quot;&gt;Please enter data in all fields.&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;error&quot;&gt;Passwords didn\'t match&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;error&quot;&gt;Username already exists, please use another one!&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;form action=&quot;register_me.php&quot; method=&quot;post&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;boxtop&quot;&gt;&lt;/div&gt;&lt;div id=&quot;boxmid&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;section&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span&gt;Username:&lt;/span&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;text&quot; name=&quot;username&quot; value=&quot;Username&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;section&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span&gt;Password:&lt;/span&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;password&quot; name=&quot;password&quot; value=&quot;Password&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;section&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span&gt;Retype Password:&lt;/span&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;password&quot; name=&quot;password2&quot; value=&quot;Password&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;&lt;div id=&quot;boxbot&quot;&gt;&lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;text&quot; style=&quot;float: left;&quot;&gt;&lt;p&gt;Already got an account ?&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;index.php&quot;&gt;Login&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;text&quot; style=&quot;float: right;&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;submit&quot; value=&quot;Register&quot; name=&quot;register&quot; class=&quot;submit&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;br style=&quot;clear:both; height: 0px;&quot; /&gt;<br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div id=&quot;bottom&quot;&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div></div>
<p><strong>register_me.php</strong><br />
At this page, we usually establish connection to the database, select the database and insert the data from registration form to the table. It is inevitable to check various aspects like if the username already exists in the table or not. Please have a look at comments in the code to be more clear about what it does.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Connect and select a datbase</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/mysql_connect"><span style="color: #990000;">mysql_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;dbuser&quot;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;dbpass&quot;</span> <span style="color: #009900;">&#41;</span>or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cannot connect to database server&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <a href="http://www.php.net/mysql_select_db"><span style="color: #990000;">mysql_select_db</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dbname&quot;</span><span style="color: #009900;">&#41;</span>or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cannot select the database&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//if form is submitted</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'register'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//check if every fields are entered</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|</span> <span style="color: #339933;">!</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|</span> <span style="color: #339933;">!</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password2'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:register.php?err=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//check if password is verified</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password2'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:register.php?err=2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//query to know whether a username already exists</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT username FROM userpass WHERE username='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$resource</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;username check error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$check</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_num_rows"><span style="color: #990000;">mysql_num_rows</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:register.php?err=3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//enter details to the table</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/addslashes"><span style="color: #990000;">addslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/addslashes"><span style="color: #990000;">addslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO userpass (username, password) VALUES ('&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$password</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;')&quot;</span><span style="color: #339933;">;</span>&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$register</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;insertion error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:index.php?reg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; <br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>After successful registration, its time to build a login form. Here, we name it as index.php<br />
<strong>index.php</strong><br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/04/login.jpg" alt="login form" /></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;html&gt;<br />
&lt;head&gt;<br />
&nbsp; &nbsp; &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; type=&quot;text/css&quot; charset=&quot;utf-8&quot;&gt;<br />
&nbsp; &nbsp; &lt;link rel=&quot;stylesheet&quot; href=&quot;style2.css&quot; type=&quot;text/css&quot; charset=&quot;utf-8&quot;&gt;<br />
&nbsp; &nbsp; &lt;title&gt;Login&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id=&quot;main&quot;&gt;<br />
&nbsp; &nbsp; &lt;div id=&quot;top&quot;&gt;&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div id=&quot;middle&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'reg'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;Registration succesfull, please login&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;Logged out Succesfully!&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;Login System&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;error&quot;&gt;Pleae enter both username and password&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;error&quot;&gt;Incorrect username or password&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;form action=&quot;checklogin.php&quot; method=&quot;post&quot;&gt;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;boxtop&quot;&gt;&lt;/div&gt;&lt;div id=&quot;boxmid&quot;&gt;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;section&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span&gt;Username:&lt;/span&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;text&quot; name=&quot;username&quot; value=&quot;Username&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;section&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span&gt;Password:&lt;/span&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;password&quot; name=&quot;password&quot; value=&quot;Password&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;&lt;div id=&quot;boxbot&quot;&gt;&lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;text&quot; style=&quot;float: left;&quot;&gt;&lt;p&gt;Haven't got an account? Want one?&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;register.php&quot;&gt;Register&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;text&quot; style=&quot;float: right;&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;submit&quot; value=&quot;Login&quot; name=&quot;login&quot; class=&quot;submit&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;br style=&quot;clear:both; height: 0px;&quot; /&gt;<br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div id=&quot;bottom&quot;&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div></div>
<p>The form at index.php (login form) POSTs data to checklogin.php. This file checks if the provided login is valid or not.<br />
<strong>checklogin.php</strong></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//connect and select db</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/mysql_connect"><span style="color: #990000;">mysql_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;dbuser&quot;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;dbuser&quot;</span> <span style="color: #009900;">&#41;</span>or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cannot connect to database server&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <a href="http://www.php.net/mysql_select_db"><span style="color: #990000;">mysql_select_db</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dbname&quot;</span><span style="color: #009900;">&#41;</span>or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cannot select the database&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//check if form is submitted</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//check if every field is entered</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|</span> <span style="color: #339933;">!</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:index.php?err=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//check if username and pass exists in db</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM userpass WHERE username='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' and password='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$password</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$resource</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$count</span><span style="color: #339933;">=</span><a href="http://www.php.net/mysql_num_rows"><span style="color: #990000;">mysql_num_rows</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//if yes, start session and set a variable</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/session_start"><span style="color: #990000;">session_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logged_in'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:loggedin.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//if not, redirect back to login page showing an error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:index.php?err=2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>If login is successful, loggedin.php is loaded. If checks for the session variable, whether it&#8217;s set or not. If it&#8217;s set. it means the user is logged in and shows an logout button which would unset the session variable.<br />
<strong>loggedin.php</strong><br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/04/logged.jpg" alt="logged in" /></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//start session and check if session variable is set</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/session_start"><span style="color: #990000;">session_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logged_in'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:index.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// if yes, show status and an logout button</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;logged in&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//if logout button is clicked, unset the session variable and redirect to index.php?logout</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logged_in'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location:index.php?logout&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>loggedin.php?logout<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Logout&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>You can then click the logout button and it will unset the session variable and redirect to index.php?logout, which looks something like<br />
<img src="http://www.anildewani.com/wp-content/uploads/2010/04/loggedout.jpg" alt="logged out" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/building-an-login-system-in-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Rapidshare Download Manager Script in Bash</title>
		<link>http://www.anildewani.com/rapidshare-download-manager-script-in-bash/</link>
		<comments>http://www.anildewani.com/rapidshare-download-manager-script-in-bash/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 11:12:48 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[getopts]]></category>
		<category><![CDATA[rapidshare]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=89</guid>
		<description><![CDATA[Just developed a simple and dirty rapidshare download manager script in bash. You can pass on the links via STDIN and the script would download them one by one. All the downloaded data is saved in /downloads directory. The script also generates a simple log file named &#8220;downloads.log&#8221; in the /downloads directory. The script works [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" src="http://vavai.net/wp-content/uploads/2010/01/bash-script.png" alt="" height="100" width="100"/>Just developed a simple and dirty rapidshare download manager script in bash. You can pass on the links via STDIN and the script would download them one by one. All the downloaded data is saved in /downloads directory. The script also generates a simple log file named &#8220;downloads.log&#8221; in the /downloads directory. The script works only for premium rapidshare account users. You need to pass username and password of your rapidshare premium account via command line switches -u and -p respectively.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #666666; font-style: italic;"># Rapidshare Download Manager script</span><br />
<span style="color: #666666; font-style: italic;"># coder : Anil Dewani</span><br />
<br />
howto<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\<br />
</span>&nbsp; &nbsp; Rapidshare Download Manager Script <span style="color: #000099; font-weight: bold;">\<br />
</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; Usage : $0 -u &lt;username&gt; -p &lt;password&gt; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &lt;username&gt;&nbsp; Rapidshare premium account username <br />
&nbsp; &nbsp; &lt;password&gt;&nbsp; Rapidshare premium account password <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; This script is used to download a queue of rapidshare files. <br />
&nbsp; &nbsp; It will create a 'downloads' directory. That's where all your <br />
&nbsp; &nbsp; downloaded files are saved.<br />
&nbsp; &nbsp; A downloads.log file would also be created in the downloads directory<br />
&nbsp; &nbsp; it will display your download logs.<br />
&nbsp; &nbsp; &quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #007800;">USER</span>=<br />
<span style="color: #007800;">PASS</span>=<br />
<br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">getopts</span> <span style="color: #ff0000;">&quot;u:p:&quot;</span> OPTION<br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$OPTION</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; u<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">USER</span>=<span style="color: #007800;">$OPTARG</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; p<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">PASS</span>=<span style="color: #007800;">$OPTARG</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ?<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; howto<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">esac</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$USER</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$PASS</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; howto<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Enter rapidshare links and press ctrl + D when you are done.. &quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> links<br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Thanks for the links&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Download Queue starting...&quot;</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> .<span style="color: #000000; font-weight: bold;">/</span>downloads <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<br />
<br />
<span style="color: #007800;">lines</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> links <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">c</span>=<span style="color: #000000;">1</span>; c<span style="color: #000000; font-weight: bold;">&lt;</span>=<span style="color: #800000;">${lines}</span>; <span style="color: #c20cb9; font-weight: bold;">c++</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #007800;">link</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> links <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #800000;">${c}</span>p<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#check if link is an valid rapidshare.com link</span><br />
&nbsp; &nbsp; <span style="color: #007800;">match</span>=<span style="color: #ff0000;">&quot;rapidshare.com&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${link}</span>&quot;</span> =~ <span style="color: #ff0000;">&quot;<span style="color: #007800;">${match}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">st</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">name</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${link}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;/&quot;</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># login and store cookiefile</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; curl \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">--cookie-jar</span> rapidsharecookie \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">--data</span> <span style="color: #ff0000;">&quot;login=<span style="color: #007800;">${USER}</span>&amp;password=<span style="color: #007800;">${PASS}</span>&quot;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; https:<span style="color: #000000; font-weight: bold;">//</span>ssl.rapidshare.com<span style="color: #000000; font-weight: bold;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;">/</span>premiumzone.cgi \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Downloading ... <span style="color: #007800;">${link}</span>&quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># download file using the cookiefile </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; curl -<span style="color: #666666; font-style: italic;"># -L -o &quot;./downloads/${name}&quot; --cookie rapidsharecookie ${link}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># write to the log</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Start: <span style="color: #007800;">${st}</span> &nbsp;<span style="color: #007800;">${link}</span> &nbsp;End: <span style="color: #780078;">`date`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>downloads.log<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Link number <span style="color: #007800;">${c}</span> is not a valid rapidshare link! This link will not be downloaded!&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> links<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> rapidsharecookie</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/rapidshare-download-manager-script-in-bash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>what does &gt; /dev/null 2&gt;&amp;1 mean ?</title>
		<link>http://www.anildewani.com/confused-about-what-does-devnull-21-means/</link>
		<comments>http://www.anildewani.com/confused-about-what-does-devnull-21-means/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 11:01:27 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[>]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[STDERR]]></category>
		<category><![CDATA[STDIN]]></category>
		<category><![CDATA[STDOUT]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=84</guid>
		<description><![CDATA[Ever been confused seeing those funny greater than signs being used on a unix system ? Let me try to explain those weird commands. The greater than sign means the output is being redirected somewhere else. Let&#8217;s have a look at an example to be more clear. wget ${url} &#62; /dev/null 2&#62;&#38;1 In this example, [...]]]></description>
			<content:encoded><![CDATA[<p>Ever been confused seeing those funny greater than signs being used on a unix system ? Let me try to explain those weird commands.</p>
<p>The greater than sign means the output is being redirected somewhere else. Let&#8217;s have a look at an example to be more clear.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #800000;">${url}</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></div></div>
<p>In this example, something is being redirected to /dev/null and something else is being redirected to &#038;1. </p>
<p>Before moving further, lets discuss about STDIN,STDOUT, and STDERR. These are the 3 sources of input and output for any particular program. STDIN means Standard Input, STDOUT means Standard Output, and STDERR means Standard Error. They are numerically denoted as 0, 1 and 2 respectively. If you do not name or number any of them, that particularly means you are talking about STDOUT. </p>
<p>Getting back to the example, </p>
<li> > /dev/null means that STDOUT is being redirected to /dev/null. It is known as bit-bucket and everything being written there is discarded automatically. </li>
<li> 2>&#038;1 means 2 (i.e STDERR) is being redirected to &#038;1 (i.e where the STDOUT is going. In this case /dev/null ). </li>
<p>That means, using > /dev/null 2>&#038;1 can be used to make any program work quietly with no STDOUT and/or STDERR. </p>
<p>This can also be done alternatively as</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</div></div>
<p>It&#8217;s still the same.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/confused-about-what-does-devnull-21-means/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking domain availability using PHP</title>
		<link>http://www.anildewani.com/check-if-domain-is-registered-or-not-using-php/</link>
		<comments>http://www.anildewani.com/check-if-domain-is-registered-or-not-using-php/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 15:12:28 +0000</pubDate>
		<dc:creator>Anil Dewani</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[fsockopen]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[whois]]></category>

		<guid isPermaLink="false">http://www.anildewani.com/?p=76</guid>
		<description><![CDATA[There are many whois servers around the interweb, we can use such whois server to determine if an domain name is already taken or is still available to be registered. Mostly whois server are connected on port 43. Below is the php script i developed to check domains with com,net,org,info,biz and name extensions. &#60;?php function [...]]]></description>
			<content:encoded><![CDATA[<p>There are many whois servers around the interweb, we can use such whois server to determine if an domain name is already taken or is still available to be registered. Mostly whois server are connected on port 43. Below is the php script i developed to check domains with com,net,org,info,biz and name extensions. </p>
<pre name="code" class="php">
&lt;?php
function checkdomain($domainname)
{
	$extension = explode(".",$domainname);
	$extension = $extension[1];
	switch($extension)
	{
		case "com": $server = "whois.verisign-grs.com"; break;
		case "net": $server = "whois.verisign-grs.com"; break;
		case "org": $server = "whois.pir.org"; break;
		case "info": $server = "whois.afilias.net"; break;
		case "biz": $server = "whois.biz"; break;
		case "name": $server = "whois.nic.name"; break;
		default: return "Given Extension not supported"; exit();
	}
    // connecting to the whois server.
    $handle = fsockopen($server, 43);
    if (!$handle)
        return false; // connectin failure 

    //asking the server
    fwrite($handle, $domainname."\r\n");

    // getting response
    $response = '';
    while (!feof($handle))
        $response .= fgets($handle, 1024);

    fclose($handle);
	//checking if domain is available or not
	if($extension=="com" || $extension=="net" || $extension=="name")
	{
		if(stripos($response, 'No match') === FALSE )
			return $domainname." is not Available!";
		else
			return $domainname. " is Available!";
	}
	else
	{
		if(stripos($response, "NOT FOUND") === FALSE)
			return $domainname. " is not Available!";
		else
			return $domainname. " is Available!";
	}
}
echo checkdomain("anildewani.com");
echo checkdomain("anildewani.net");
echo checkdomain("anildewani.org");
echo checkdomain("anildewani.info");
echo checkdomain("anildewani.biz");
echo checkdomain("anildewani.name");
echo checkdomain("anildewani.in");
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.anildewani.com/check-if-domain-is-registered-or-not-using-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

