How to Create Login Page in PHP and MySQL with Session

November 24, 2007

==========================
Due to a lot of problem reported by friends about these script writing, so here I put the complete scripts. You can grab it here: http://rapidshare.com/files/195043222/login-frozenade.co.nr.zip
Thank you for concern. :)
==========================

The production of login page using PHP and MySQL is actually very simple.

I assume that you use local PHP connection and your MySQL database configuration use ‘localhost’ as hostname and ‘root’ as user with blank password.

First, let’s create a database:
create database dblogin;

Then use our database we’ve just created with command:
use dblogin;

Now, let’s create a table:
create table tbuser
(username varchar(50),
password varchar(255))

After that, fill the table with username ‘admin’ and password ‘adminpass’.
insert into tbuser values ('admin',md5('adminpass'));

Now, let’s prepare the login page.
<html>
<head>
<title>login page</title>
</head>
<body>
<form method="POST" action="loginproc.php">
<p>username: <input type="text" name="username" size="20"></p>
<p>password: <input type="text" name="password" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>

Save above document with name ‘loginpage.php’.

Now, prepare a file and give it name ‘loginproc.php’ to check the validity of username and password.
<?
session_start();

$server = "localhost";
$username = "root";
$password = "";
$db_name = "dblogin";

$db = mysql_connect($server,$username,$password) or DIE("Connection to database failed, perhaps the service is down !!");
mysql_select_db($db_name) or DIE("Database name not available !!");

$login = mysql_query("select * from tbuser where (username = '" . $_POST['username'] . "') and (password = '" . md5($_POST['password']) . "')",$db);
$rowcount = mysql_num_rows($login);
if ($rowcount == 1) {
$_SESSION['username'] = $_POST['username'];
header("Location: securedpage.php");
}
else
{
header("Location: loginpage.php");
}
?>

As you see above, there is ’session_start();’.
This function is used to initializes a data session. It will creates a new session or continues previous session from data session change by GET, POST or cookie.
See the detail information about session here: http://id.php.net/function.session-start

If username and password are correct, then we’ll be directed to ’securedpage.php’.
This is a page that we want to show if login is successful. This page cannot be accessed if there is not found the correct data session when login is successfully passed. This page also contains ‘logout’ menu, so we can destroy our login data session then return to login page.

This is content of ’securedpage.php’:
<?
session_start();
if (!isset($_SESSION['username'])) {
header("Location: loginpage.php");
}
?>
<html>
<head>
<title>secured page</title>
</head>
<body>
<p>secured page with session <? echo $_SESSION['username']; ?></p>
<p><a href="logoutpage.php">logout</a></p>
</body>
</html>

Script for ‘logout.php’:
<? session_start();
unset($_SESSION['username']);
session_destroy();
header("Location: loginpage.php");
?>

Store your files you have created in one location. e.g: ‘logintest’.
So, the login page could be http://localhost/logintest/loginpage.php

So easy, isn’t it? ;)

==========================
Due to a lot of problem reported by friends about these script writing, so here I put the complete scripts. You can grab it here: http://rapidshare.com/files/195043222/login-frozenade.co.nr.zip
Thank you for concern. :)
==========================


New PCMedia 1.0 RC22 + Update Build1

November 21, 2007

PCMedia has launched the new release, RC22.

I’ve include an update file named Build1.
Here is the download link: http://rapidshare.com/files/71270219/PCMAV-1.0-RC22_Update-Build1.rar

Too bad, still same, very slow in loading of running process. :(
Anyway, most top rapid progress antivirus! :D

Enjoy! ;)


Space Invader Java Game

November 21, 2007

Due to request from a friend named Joshua, then this is a Space Invader game written in Java. Here you go.. ;)

Download link:  http://rapidshare.com/files/71188169/Space_Invaders.zip


Create Balloon Tips in SysTray

November 18, 2007

You may wondering how to create balloon tips in Visual Basic put in systray.

Allright then, this is how!

Option Explicit
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 128
dwState As Long
dwStateMask As Long
szInfo As String * 256
uTimeout As Long
szInfoTitle As String * 64
dwInfoFlags As Long
End TypePrivate sysTray As NOTIFYICONDATA

'Constants
Private Const NOTIFYICON_VERSION = 3
Private Const NOTIFYICON_OLDVERSION = 0

Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2

Private Const NIM_SETFOCUS = &H3
Private Const NIM_SETVERSION = &H4

Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4

Private Const NIF_STATE = &H8
Private Const NIF_INFO = &H10

Private Const NIS_HIDDEN = &H1
Private Const NIS_SHAREDICON = &H2

Private Const NIIF_NONE = &H0
Private Const NIIF_WARNING = &H2
Private Const NIIF_ERROR = &H3
Private Const NIIF_INFO = &H1
Private Const NIIF_GUID = &H4

Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private Const WM_RBUTTONDBLCLK = &H206

' API Declaration
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

Private Sub Command1_Click()

With sysTray
.cbSize = Len(sysTray)
.hWnd = Me.Picture1.hWnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_INFO Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Picture1.Picture
.szTip = " Here placing toolTip " & vbNullChar
.dwState = 0
.dwStateMask = 0
End With

Shell_NotifyIcon NIM_ADD, sysTray

End Sub

Private Sub Command2_Click()
With sysTray
.cbSize = Len(sysTray)
.hWnd = Picture1.hWnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_INFO Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Picture1
.szTip = " Here placing toolTip " & vbNullChar
.dwState = 0
.dwStateMask = 0
.szInfo = Text2 & Chr(0)
.szInfoTitle = Text1 & Chr(0)
.dwInfoFlags = NIIF_INFO
.uTimeout = 100
End With

Shell_NotifyIcon NIM_MODIFY, sysTray
End Sub

Private Sub Command3_Click()
Shell_NotifyIcon NIM_DELETE, sysTray
End Sub

Private Sub Form_Load()
Command1.Caption = " Report on Systray "
Command2.Caption = " Show Balloon dialogue "
Command3.Caption = " Remove from systray "
Text1 = App.EXEName
Text2 = " Welcome to STMIK Banjarbaru zone! "
End Sub


PCMedia AntiVirus RC 21 + Latest Update

November 14, 2007

If you like PCMedia AntiVirus, what are you waiting for? Just click link below to download it.

Download link: http://rapidshare.com/files/69687625/PCMediaAV_RC21_Update_NEW.rar