How to Create Login Page in PHP and MySQL with Session

November 24, 2007

##########################
NEW UPDATE!!!
PHPMySimpleLogin 0.3

Download full source code:
http://rapidshare.com/files/404808631/phpmysimplelogin-0.3-frozenade.co.nr.zip.html
##########################

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

I assume that you use local web server connection (Apache and PHP) and your MySQL database configuration use ‘localhost’ as hostname and ‘root’ as username with blank password.
For this case, I recommend you to using XAMPP (http://www.apachefriends.org/en/xampp-windows.html).
Please download and install it to your path choice. e.g: C:\xampp

Run XAMPP Control Panel on desktop.

Start Apache and PHP modules.

Let’s create a database with PHPMyAdmin. Open your favorite browser, then type ‘http://localhost/phpmyadmin’ at your browser address bar.

Create database ‘phpmysimplelogin’.

Click ‘Create’.

Now, let’s create a table, name it ‘user’ with ‘2’ (two) number of fields.

Click ‘Go’.

First field, name it ‘username’, type ‘varchar’, lenght/values ’25’.
Second field, name it ‘password’, type ‘varchar’, lenght/values ‘255’.

Click ‘Save’.

After that, we will fill the table. Click ‘SQL’ menu, then type this query on textbox:
INSERT INTO user (username, password) VALUES (‘admin’, md5(‘admin’))

Click ‘Go’.

It means, you fill ‘username’ field with string ‘admin’ and ‘username’ field with an encryption string of ‘admin’.
MD5 ia a function to create one-way encryption (hashing) from our password, so it can be more secure.
For detail, please check: http://www.php.net/manual/en/function.md5.php

Okay, now let’s prepare the web pages.
Create folder ‘phpmysimplelogin’ in your XAMPP’s htdocs. So, it will be ‘C:\xampp\htdocs\phpmysimplelogin’.
Remember to save all of your files you will create, inside this folder.

Run your favorite PHP code editor, e.g: PHP Expert Editor, RapidPHP, etc; or just Microsoft Notepad is fine.

Save document below with name ‘config.inc’.

<?php

$hostname = 'localhost';        // Your MySQL hostname. Usualy named as 'localhost', so you're NOT necessary to change this even this script has already online on the internet.
$dbname   = 'phpmysimplelogin'; // Your database name.
$username = 'root';             // Your database username.
$password = '';                 // Your database password. If your database has no password, leave it empty.

// Let's connect to host
mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
// Select the database
mysql_select_db($dbname) or DIE('Database name is not available!');

?>

Next step, save document below and name it as ‘index.php’:

<?php

// Inialize session
session_start();

// Check, if user is already login, then jump to secured page
if (isset($_SESSION['username'])) {
header('Location: securedpage.php');
}

?>
<html>

<head>
<title>PHPMySimpleLogin 0.3</title>
</head>

<body>

<h3>User Login</h3>

<table border="0">
<form method="POST" action="loginproc.php">
<tr><td>Username</td><td>:</td><td><input type="text" name="username" size="20"></td></tr>
<tr><td>Password</td><td>:</td><td><input type="password" name="password" size="20"></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td><input type="submit" value="Login"></td></tr>
</form>
</table>

</body>

</html>

As you see, 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 changed by GET, POST or cookie.
See the detail information about session here: http://id.php.net/function.session-start

Now, prepare a file and give it name ‘loginproc.php’ to check the validity of username and password.

<?php

// Inialize session
session_start();

// Include database connection settings
include('config.inc');

// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM user WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')");

// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Jump to secured page
header('Location: securedpage.php');
}
else {
// Jump to login page
header('Location: index.php');
}

?>

If username and password are correct, then we’ll be directed to ‘securedpage.php’.
This is the page that we want to show if login is successful. This page cannot be accessed if the correct data session is not found when login check is 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’:

<?php

// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: index.php');
}

?>
<html>

<head>
<title>Secured Page</title>
</head>

<body>

<p>This is secured page with session: <b><?php echo $_SESSION['username']; ?></b>
<br>You can put your restricted information here.</p>
<p><a href="logout.php">Logout</a></p>

</body>

</html>

This is content of ‘logout.php’:

<?php

// Inialize session
session_start();

// Delete certain session
unset($_SESSION['username']);
// Delete all session variables
// session_destroy();

// Jump to login page
header('Location: index.php');

?>

Try on your favorite browser, ‘http://localhost/phpmysimplelogin/&#8217;.

So easy cake, isn’t it? 😉

##########################
NEW UPDATE!!!
PHPMySimpleLogin 0.3

Download full source code:
http://rapidshare.com/files/404808631/phpmysimplelogin-0.3-frozenade.co.nr.zip.html
##########################


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! 😀

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


How To Download A Video From Youtube, Dailymotion, Redtube, You Porn and Many More

November 14, 2007

If you wondering how download a video from YouTube, Daily Motion, Redtube, YouPorn this time i will give you some trick. First of all you need a Mozilla Firefox, you can download it from http://www.mozilla.com to get a latest release of Mozilla Firefox. Why I choose Mozilla because they can easily add a new addons for your browser activity.

After you download and install the mozilla go to the website once again, and click Addons.

Look for the search text put on “youtube” then click Search.

You can choose many youtube addons on your mozilla, but i recommended you to use “DownloadHelper” because it can be used from many Website that contain any multimedia.

Just install the addons on your mozilla. Than restart the mozilla, just simply closed the mozilla and run it back again. Now you’re ready to download a video from a Youtube. Go to the website http://www.youtube.com then search and select your favorite movie clip.

Click on the 3 balloon icon (blue, yellow, red) beside the address navigation select the Youtube Icon than save it.

Remember the extension of the file is “flv“, you need a Adobe Flash Player, and FLV Player such as FLV Player 1.3.3 or Gom Player, or you can use Kazza Lite Video Codecs.

This is the link how you can get that player: http://www.adobe.com/products/flashplayer/


Do antivirus companies create computer viruses?

November 14, 2007

Question:
Do antivirus companies create computer viruses?

Answer:
No. Antivirus companies know the risks involved when dealing with computer viruses and the potential dangers of viruses getting out in the wild. Antivirus companies do not hire people who’ve made viruses and the whole concept of antivirus companies creating viruses is simply a myth, urban legend and conspiracy theory.

But, creating viruses help increase antivirus companies profits.
There are plenty of viruses and other malware to justify the needs of antivirus programs. If antivirus companies really believed that distributing viruses would help increase profits or sells they would create viruses and other malware for other platforms such as the Apple Macintosh and *nix where virus threats are not as high with Microsoft Windows users.

Antivirus companies are able to maintain and increase their products by keeping up-to-date at detecting and cleaning all computer viruses and other threats.

Where is your proof that antivirus companies don’t do this?
– Creating computer viruses is not that difficult for someone who’s familiar with computers and programming. Creating viruses would not help in the detection or prevention of viruses.
– An antivirus company couldn’t protect itself from the virus before it was released without raising suspicion. Therefore it would infect its own product causing customer dissatisfaction.
– There are plenty of other users who are not affiliated with antivirus companies who already do this.
– The code that makes up a virus is reviewed by dozens of security experts when a virus gets out in the wild. Analyzing that code could trace its origins back to the antivirus company.
– Many experts can determine the origination of viruses, which could potentially track back to an antivirus company.
– An antivirus company could be held liable for creating viruses, which would not only make the company look bad but could cause a lot of lawsuits.

Source: Computer Hope