Sunday, July 25, 2010

Creating advanced and secured member login/register system using PHP and MySQL

Posted: 28 Apr 2010 07:24 AM PDT

In this tutorial, I am going to teach you how to create a simple login system using PHP and MySQL database.
Before beginning, I am making assuming that you have basic knowledge on PHP coding. However you may understand what I am doing if you have basic programming concepts.

Now let us summarize what we’ll be doing.

First we’ll be creating a database table with username, password and email (optional) columns. After creating the database, we’ll be using two input forms to login in login.php page. And three input forms in register.php. Then we’ll be verifying the entered username and password value with that on in the MySQL database disabling the un-authorized access to the specific part of your page. If your password matches with the record in the database then you’ll be automatically redirected to member.php which is only accessible to members.

For login

For register

So let’s begin.

First create a database:

//connects to the database

$con= mysql_connect(“localhost”, “username”, “password”);

// creates command new database named user_logs

$dbase= “CREATE DATABASE user_logs”;

//creates new database using mysql_query function.

mysql_query($dbase, $con);

//selects recently created user_logs database

mysql_select_db(“user_logs”, $con);

//creates new user table with columns in user_logs dtabase.

$sqls = “CREATE TABLE user

(

username VARCHAR(15),

password VARCHAR(15),

email VARCHAR(50),

userID int NOT NULL AUTO_INCREMENT,

PRIMARY KEY(userID)

)”;

// Execute query

mysql_query($sqls, $con);

// closes the connection.

mysql_close($con);

?>

In the above setup, username and password have maximum number of character limited to 15.

You can add other columns to the table.

For example, if you want email address too then refer to the following sample of MySQL command.

CREATE TABLE table_name

(

Column1 VARCHAR(15),

Column2 VARCHAR(15),

Column3 VARCHAR(50),

columnID int NOT NULL AUTO_INCREMENT,

PRIMARY KEY(columnID)

)”;

Now we are done with the database. Save the above file as “create_db.php”.

Creating register form:

Name:

password:

email:

Now lets make a backend code using PHP.

//connects to the database.

$con= mysql_connect(“localhost”, “root”);

// if everything is empty then returns with message.

if (empty($_POST["user"]) || empty($_POST["pwd"]) || empty($_POST["mail"]) && isset($_POST["save"]))

{

echo “Please enter your username with maximum 15 characters and password with maximum 15 characters properly with valid email ID.”;

}

// if values are properly posted, applies md5 hash to the password.

if (isset($_POST["save"]) && $_POST["user"] && $_POST["pwd"] && $_POST["mail"])

{

$user = $_POST["user"];

$_POST['pwd'] = md5($_POST['pwd']);

$pwd = $_POST['pwd'];

$mail = $_POST["mail"];

}

// again when the value are properly posted, queries the database if the same username exists. If true then returns with message else writes on the database.

if (isset($_POST["save"]) && $_POST["user"] && $_POST["pwd"] && $_POST["mail"])

{

mysql_select_db(“user_logs”, $con);

$checkuser = mysql_query(“SELECT username FROM user WHERE username=’$user’”);

$username_exist = mysql_num_rows($checkuser);

}

if($username_exist > 0)

{

echo “The username you’ve request has already been taken, please try any other username.”;

}

elseif (isset($_POST["save"]) && $_POST["user"] && $_POST["pwd"] && $_POST["mail"]) {

mysql_select_db(“user_logs”, $con);

$write = “INSERT INTO user (username, password, email) VALUES (‘$user’, ‘$pwd’, ‘$mail’)”;

mysql_query($write, $con);

echo “Congraturlations, you’ve been registered”;

mysql_close($con);

}

?>


Already registered? Click here to Login

Save the above PHP script and register form in separate register.php file.

Now we will be creating forms for login and registration.

The form below is for login.php.

Name:

password:

This time we’ll be applying this form inside the PHP backend code instead of applying it separately as we did with register.php.

The above form contains a submit button with username and password input field.

The backend part of login.php is somewhat complex. Before using the code below, let me tell you what it does.

As the page loads, it checks for the existence of cookies in your browser. If you have cookies already been set then it verifies it with the mysql database. If it comes true then it will redirect login.php to member.php(where your member’s page resides).

But if you don’t have cookies set in your browser, then it will load a user login form. When you log in, if the username and password matches with the one in database it will set a cookies for both username and password in your browser. And finally redirect your page to member.php. Else if your login information doesn’t matches, it returns with Try-again message and a login form.

//Checks if the cookie exists, if true then verifies it with the database.

if (isset($_COOKIE['user']) && isset($_COOKIE['pass']))

{

$usar = $_COOKIE['user'];

$pswd = $_COOKIE['pass'];

$con = mysql_connect(“localhost”, “root”) or die(“cannot connect”);

mysql_select_db(“user_logs”, $con) or die(“cannot select DB”);

$sql=”SELECT * FROM user WHERE username=’$usar’”;

$result=mysql_query($sql, $con);

$info=mysql_fetch_array($result);

//if verified redirects your page to member.php

if (mysql_num_rows($result)==1 && $pswd!= $info['password'])

{

header (“Location: member.php”);

}

}

// other wise if you don’t have cookies set you’ll already be welcomed with the login form which is executed from the bottom of this PHP page. And if you input your username and password it will check and verify with the mysql database.

if (isset($_POST['save']))

{

$con = mysql_connect(“localhost”, “root”) or die(“cannot connect”);

mysql_select_db(“user_logs”, $con) or die(“cannot select DB”);

$user = $_POST["user"];

$pwd = md5($_POST['pwd']);

$sql=”SELECT * FROM user WHERE username=’$user’”;

$result=mysql_query($sql, $con);

$info=mysql_fetch_array($result);

if (mysql_num_rows($result)==1 && $pwd!= $info['password'])

{

$hour = time() + 60;

setcookie(user, $_POST['user'], $hour);

setcookie(pass, $_POST['pwd'], $hour);

header (“Location: member.php”);

}

//if false user information then returns with try-again message and a login form.

else {

echo “Access denied. Try re-entering your username and password, if you haven’t registered yet, Click here to register”;

echo “Login module”;

echo “

”;

echo “Name: ”;

echo “password: ”;

echo “”;

echo “

”;

}

}

// if nothing is true or neutral then loads login form only.

else {

echo “Login module”;

echo “

”;

echo “Name: ”;

echo “password: ”;

echo “”;

echo “

”;

}

?>

You may be wondering why I used cookies. This is because, if you mistakenly or by change went to login.php, you won’t have to re-enter your username and password again and again.

Now we’ll create a secure page where only members can access. If guests or other tries to access to this page it will prompt for the username and password.

Again we’ll be checking if the cookies exists or not, if the cookies value matches with database, it will welcome you to your member’s page. This is then a secured page where only people with proper username and password can access.

if (isset($_COOKIE['user']) && isset($_COOKIE['pass']))

{

$user = $_COOKIE['user'];

$pwd = $_COOKIE['pass'];

$con = mysql_connect(“localhost”, “root”) or die(“cannot connect”);

mysql_select_db(“user_logs”, $con) or die(“cannot select DB”);

$sql=”SELECT * FROM user WHERE username=’$user’”;

$result=mysql_query($sql, $con);

$info=mysql_fetch_array($result);

if (mysql_num_rows($result)==1 && $pwd!= $info['password'])

{

echo “Welcome “;

echo $_COOKIE['user'];

echo ” to your main page.”;

}

else

{echo “Sorry wrong password”;}

}

else {

include (“login.php”);

}

Instead of following block of codes,

echo “Welcome “;

echo $_COOKIE['user'];

echo ” to your main page.”;

you can add other codes here, for example details of user and their inputs with dynamic webpage.

Note: you may also apply addcslashes() function to every inputs from input forms to get rid of MySQL injections. Make sure that your mysql Host, Username and Password is right one.

Hope from this tutorial you got cleared how to create a PHP and MySQL based secure and advanced login system for your browser.

If you have any question please comment in this blog.

Saturday, July 24, 2010

Creating Realistic road texture using Photoshop CS4

Posted: 27 Apr 2010 10:09 AM PDT

Today I am teaching you how to create a realistic texture of road and apply it to your image.

There are various techniques to create the texture of road. In this tutorial, I am going to create a texture of rough road with cracked pitch.

Follow by step by step tutorial below.

First of all create a Photoshop document of default format and size but change the Background Contents to Transparent.

Now in your tools bar choose the foreground color as dark gray (#2d2d2d) instead of completely black.

Select the Layer 1 and press ALT + Backspace to fill the dark gray color to the whole document.

Then apply noise to the background by going to Filter>Noise>Add Noise. Check on Monochromatic and apply uniform distribution by checking on Uniform radio button, put the amount value about 2 %.

Now since we’ve applied the rough texture of road, we’ll now create the cracked spots, to do so, create a new transparent layer (Ctrl + Shift + N).

Apply the cloud render filter (Filter>Render>Cloud) keep pressing CTRL + F (re-filter) to get the satisfactory cloud (one with large dark areas than white/gray).

Again after applying cloud render, go to Filter>Render>Difference Cloud to apply difference cloud render.

Now configure the level value of the cloud layer (Layer 2) by pressing CTRL + L. Put the values or move the sliders as shown in the figure.

Now hide the Layer 2 by clicking on eye icon on the layer panel.

Create a new layer , Layer 3.

And apply the road dividers using marquee tool and fill it with white colour.

In layer panel, click on “fx” icon as shown in figure and choose on Blending Options, or directly right click on Layer 3 and choose blending options.

In the blending options window, move the black slider (highlighted in the image below). To separate the joined black slider hold down ALT and draw the slider left or right to get the satisfactory result of the divider scratch.

Make Layer 2 visible by clicking on the visibility icon as shown in image. (Since you’ve hide it before there won’t be icon, when you click it the eye icon will again load)

Blend the layer to Overlay and decrease the opacitiy to 20% for Layer 2.

Choose an eraser tool (E) and get some rough brush by right clicking on the art board and slightly delete the edges. You can decrease the opacity and flow from options bar.

Apply some brushes to make it look more white than in the divider zone as the road gets smooth on the region where vehicle moves.

Now you’ve the road ready. You can apply it to any picture you want.

To apply it to the image just transform, skew and distort it according to the demand of your main picture.

Merge all the layers and bring the main picture just below the road.

Here you’ve the road ready.

Hope you find this tutorial helpful.

Friday, July 23, 2010

Adding Category Based Recent Posts In Blogger

Posted: 24 Apr 2010 04:05 AM PDT

You may want to have the widget like category based recent post listing. If you have wordpress blog then it’s not so big deal because Wordpress has world’s stable and independent blogging platform.

But if you are using blogger you may really get apart from such flexibilities.

Let’s not make any complex stories and just tell you how to add Category or label based recent post without using any external javascript or codes.

I am going to show you simple hack for the default widget by blogger which shows recent posts chronologically from any RSS source you define.

To call the latest posts from the specific Label or Category you can also apply a simple tweak as following to blogger’s FEED widget.

First go to Layout tab> Page elements, after logging in to your blogger dashboard.

Click on Add a gadget link in the layout page.

A new window will open, search and click on Feed widget from your blogger layout.

Then in the feed URL, include your feed URL in following format:

http://YOUR_BLOG_NAME.blogspot.com/feeds/posts/default/-/YOUR_CATEGORY_OR_LABEL/

This will list all the posts labeled in YOUR_CATEGORY_LABEL. Replace it with your own label.

Add as much widget as you need for your specific category.

And you are done.

View live demo here.

Hope this trick was helpful.

Thursday, July 22, 2010

How To Abort The Mistaken Shutdown Operation In Windows

Posted: 23 Apr 2010 03:56 AM PDT

You’ve mistakenly pressed shutdown button on your pc or you mistakenly choose restart. In such condition, how to abort the current shutdown operation?

With a simple command it’s easy to abort the on going shutdown operation.

To abort shutdown, immediately after initiating shutdown, press Windows + R (Start>Run) and type the following command.

Shutdown –a

Note this command may not work if the shutdown operation have already closed the explorer.exe.

Further more typing opening run command and typing there may take time which may loose the chance to abort shutdown.

To not to make it happen, we’ll create an emergency abort shutdown icon. Then you’ll just have to double click on it to abort shutdown.

To create an emergency shutdown icon:

Let’s create a shortcut to shutdown –a command in desktop.

To do so, right click on the blank area of your desktop and choose New>Shortcut

In input box of “type the location of the item” copy or type the following command as shown in image below:

Give it your own shortcut name. (I named it Emergency)

Click on Finish button.

You’ll have your emergency abort shutdown icon ready. Now to easily recognize it, we’ll give it a unique icon and place it at the unique place (i.e. apart from other icons in desktop)

Right click on the Emergency icon that you just created, go to Properties and click on Change icon button at the bottom.

Then choose your unique icon and click OK.

Place it wherever you like, preferably apart from the common desktop icons(this may help you easily find the icon whenever you need it in hurry).

This will abort the shutdown.

Hope this tutorial was helpful.

Wednesday, July 21, 2010

Create Your Own Fonts With Windows Bult-in Utility

Posted: 22 Apr 2010 03:51 AM PDT

Today, let me show you how to create your own characters or set of characters (Fonts) using built-in utility of windows.This utility is called Private Character Editor, it also works side by side with Character Mapping utility of windows (Start>All Programs>Accessories>System Tools>Character Map)

Private Character Editor is located inside system32 folder in WINDOWS folder.

To run Private character editor, go to Start>Run and type the following:

%systemroot%\system32\eudcedit.exe or simply type “eudcedit.exe” without quotes.

You’ll be welcomed in Private character editor with Select Code window.

Choose any of the blank box and click OK.

You’ll be welcomed in Edit window with a grid measuring 50 X 50.


Each character that you draw becomes a black and white bitmap (*.bmp).

The drawing art board is simple enough to understand, but it needs some tricky art to draw a character in it. Use the left mouse button to draw in black and the right one to erase it.

You can choose several tools from Tools menu, also you can rotate it.

After you are satisfied with your own private character, you can save it with your own hexadecimal value.

  • To save a private character with the hexadecimal code shown on the guidebar, on the Edit menu, click Save Character.
  • To save a private character with a different hexadecimal code, on the Edit menu, click Save Character As.

To use your private characters in a program such as Notepad.

  1. Open Character Map(Start>All programs>Accessories>System Tools>Character Map) .
  2. In the Font list, click the font that is linked to the private characters you want to use.

This font name contains the words Private Characters in parentheses. For example, if you linked your private characters to the Times New Roman Font, click Times New Roman (Private Characters). If you have linked your private characters to all fonts, click All Fonts (Private Characters).

  1. Click the private character you want to use, click Select, and then click Copy.
  2. Open the program you want to use the private character in. For the purposes of illustration, you can open Notepad.
  3. In Notepad, on the Format menu, click Font, and then select the font that is linked to the private character you want to use.

This font should be the same font you selected in step 2 of this procedure.

  1. In Notepad, on the Edit menu, click Paste.

The private character is inserted into the Notepad document.

Hope this tool might come pretty handy for vector and graphics designers.

Tuesday, July 20, 2010

How To Add Random Posts Widget In Blogger

Posted: 21 Apr 2010 03:18 AM PDT

Your readers only see the recent (just published) post. They are not able to see your older quality contents. Because there is no any other option to bring up your older post in blogger. I’ve made a simple javascript module that can fetch out random post from your feeds including your older posts. This can help you to show each older or inner post of your blog.

How to add this widget to your blogger blog.

Logon to Blogger

Go to Layout > Add a Gadget

Click on HTML/JAVASCRIPT

Paste the below code to the pop up window which that you just open. Give it tile Random Post.

You can change the number of links to display. Change the number highlighted in red to your needs. It depends upon you how many post link you want to display.

And click Save.

Now result should look like this:

Hope this was helpful to you. Now, your reader can see your each blogger post.

Saturday, July 17, 2010

Hunt For The Administrator’s Page Using PHP Program

Posted: 20 Apr 2010 03:09 AM PDT

Today I am going present you a new PHP tutorial which will enable hackers like you to find the administrator page without any hassle.
Let’s get started with the tutorial.

First of all I am going to create a form where you’ll have to input the URL of the website.

Create a basic HTML platform in a new text file with HTML, BODY, TITLE tag etc.

Creating a form:

http://www.website.com/”/>


Now let’s do some PHP magic after the form.

What we are going to do in PHP magic is to search the specified directory. Many websites usually keeps the administrator page separately on the folder with specific name given.

What we are going to do is execute the following code and find the administrator page folder.

Trying out and guessing different form might be tedious job therefore, we’ll create a new text file named folders.txt with the list of our guessed directory.

/** Let’s ensure that the page does not timeout unexpectedly hampering our search job**/

set_time_limit(0);

$Target = $_POST['targetSite'];

//this function will only execute if the target is provided.

if ($Target <> “”) {

echo ‘
Starting
’;

$url = $_POST['targetSite'];

echo “
Targeting: “.$Target.”

”;

//This function will check for the file named folders.txt which contains the list of suspected administrator folders.

$MasterList = ‘folders.txt’;

// This function will clear the cache to ensure that the status of the file is checked

clearstatcache();

if (file_exists($MasterList)) {

echo “Retrieving List
”;

} else {

echo “The file $MasterList does not exist”;

}

//Open the file and assign each line to a new element in the array

//Once completed, close the file

$fHandler = fopen($MasterList, “r”);

while (! feof($fHandler)) {

$thisline = fgets($fHandler);

$adminfolder = file($MasterList);

}

fclose($fHandler);

//This function will try to access each URL and returns the list of URLs that do not respond with 404 error(Page not found error)

foreach ($adminfolder as $adminurl){

$headers = get_headers(“$Target$adminurl”);

if (eregi(‘Not Found’, $headers[0])) {

echo “$Target$adminurl NO!
”;

}

else {

echo “$Target$adminurl Here is the URL of ADMIN Page!
”;

}

}

}

?>

The folders.txt will be as follow:

admin/

administrator/

moderator/

webadmin/

adminarea/

bb-admin/

adminLogin/

admin_area/

panel-administracion/

instadmin/

memberadmin/

administratorlogin/

adm/

cmsadmin/

administrator/index.php

wp-admin/

cms/

beheer/

webmaster/

web-master/

web-beheerder/

webbeheerder/

bestuur/

intranet/

intronet/

staff/

staff/index.php

staff/login.php

staff/members.php

staff/member.php

personeel/

personeel/login.php

personeel/index.php

account/index.php

account/

manager/index.php

manager/

manage/

manage/index.php

controlemanager/

admin1.php

admin1.html

admin2.php

admin2.html

yonetim.php

yonetim.html

yonetici.php

yonetici.html

adm/

admin/

admin/account.php

admin/account.html

admin/index.php

admin/index.html

admin/login.php

admin/login.html

admin/home.php

admin/controlpanel.html

admin/controlpanel.php

admin.php

admin.html

admin/cp.php

admin/cp.html

cp.php

cp.html

administrator/

administrator/index.html

administrator/index.php

administrator/login.html

administrator/login.php

administrator/account.html

administrator/account.php

administrator.php

administrator.html

login.php

login.html

modelsearch/login.php

moderator.php

moderator.html

moderator/login.php

moderator/login.html

moderator/admin.php

moderator/admin.html

moderator/

account.php

account.html

controlpanel/

controlpanel.php

controlpanel.html

admincontrol.php

admincontrol.html

adminpanel.php

adminpanel.html

admin1.asp

admin2.asp

yonetim.asp

yonetici.asp

admin/account.asp

admin/index.asp

admin/login.asp

admin/home.asp

admin/controlpanel.asp

admin.asp

admin/cp.asp

cp.asp

administrator/index.asp

administrator/login.asp

administrator/account.asp

administrator.asp

login.asp

modelsearch/login.asp

moderator.asp

moderator/login.asp

moderator/admin.asp

account.asp

controlpanel.asp

admincontrol.asp

adminpanel.asp

fileadmin/

fileadmin.php

fileadmin.asp

fileadmin.html

administration/

administration.php

administration.html

sysadmin.php

sysadmin.html

phpmyadmin/

myadmin/

sysadmin.asp

sysadmin/

ur-admin.asp

ur-admin.php

ur-admin.html

ur-admin/

Server.php

Server.html

Server.asp

Server/

wp-admin/

administr8.php

administr8.html

administr8/

administr8.asp

webadmin/

webadmin.php

webadmin.asp

webadmin.html

administratie/

admins/

admins.php

admins.asp

admins.html

administrivia/

Database_Administration/

WebAdmin/

useradmin/

sysadmins/

admin1/

system-administration/

administrators/

pgadmin/

directadmin/

staradmin/

ServerAdministrator/

SysAdmin/

administer/

LiveUser_Admin/

sys-admin/

typo3/

panel/

cpanel/

cPanel/

cpanel_file/

platz_login/

rcLogin/

blogindex/

formslogin/

autologin/

support_login/

meta_login/

manuallogin/

simpleLogin/

loginflat/

utility_login/

showlogin/

memlogin/

members/

login-redirect/

sub-login/

wp-login/

login1/

dir-login/

login_db/

xlogin/

smblogin/

customer_login/

UserLogin/

login-us/

acct_login/

admin_area/

bigadmin/

project-admins/

phppgadmin/

pureadmin/

sql-admin/

radmind/

openvpnadmin/

wizmysqladmin/

vadmind/

ezsqliteadmin/

hpwebjetadmin/

newsadmin/

adminpro/

Lotus_Domino_Admin/

bbadmin/

vmailadmin/

Indy_admin/

ccp14admin/

irc-macadmin/

banneradmin/

sshadmin/

phpldapadmin/

macadmin/

administratoraccounts/

admin4_account/

admin4_colon/

radmind-1/

Super-Admin/

AdminTools/

cmsadmin/

SysAdmin2/

globes_admin/

cadmins/

phpSQLiteAdmin/

navSiteAdmin/

server_admin_small/

logo_sysadmin/

server/

database_administration/

power_user/

system_administration/

ss_vms_admin_sm/

Now finally lets arrange the whole thing that we’ve created in one place.

Create new text file or use dreamweaver and copy the form and paste below the form paste the PHP code. Finally rename it as adminsearch.php

Place both adminsearch.php and folders.txt in one separate folder and upload it to your web host or local host. Go to the URL that have adminsearch.php and hunt for the administrator’s page for the target website.

Now since you got the location of administrator page, you can play something further to hack in to administrator’s page.