Archive

Posts Tagged ‘tutorial’

Multi-Argument Parsing

March 15th, 2010 admin No comments

Well, it has been some time since my last post since I have been (and still am) very busy, but I felt I needed to update! I wrote a quick script for you guys to help in any programming endeavors you may be having parsing your command line arguments in any command line program. This example merely shows how to simply print all the arguments given to a specified program, however, you can use this type of loop to do whatever you wish!

/**
* Process Command Line Args
* Level: Easy
* Author: Dennis J. McWherter, Jr.
*
*/

#include <iostream>

using namespace std; // I'll save myself some std::<> pain this time XD

void echo(char* str,int no)
{
int x = strlen(str);
cout<< "Argument Number "<< no << ": ";
for(int i=0;i<x;i++){
cout<< str[i];
}
cout<< endl;
}

int main(int argc,char* argv[])
{
for(int i=1;i<argc;i++){
echo(argv[i],i);
}
cout<< endl<< "Command line: "<< argv[0] << endl;
return 0;
}

As you can see, the first function is a loop which is given a char* array (it loops through each array value to print out the full string) and an integer position. The int allows the script to know which argument number it is processing (not that it is imperative in this case). In the int main(); function, this void echo(); function is called in another for(); loop. This loop begins at array position 1 (the array starts at position 0, however, arguments begin at 1; 0 is the program/command line name). Therefore, for each argument listed the program loops until it reaches it has no further arguments to parse.

There is your quick lesson today in processing multiple arguments in the command line! This should help many of you looking for a quick and easy solution to do this! The example code is provided below for download.

Regards,
Dennis M.

Parse Multiple Arguments

PHP & Pagination

June 4th, 2009 admin No comments

Very often I see people asking questions about this on forums such as DP and NP. I have probably posted my code snippet on how to efficiently create a simple pagination document more times than I can count (which whether you believe it or not is pretty high ;) ). So I decided I’d go through it here.

First off, we’ll explain what pagination is. You may be reading this article not even certain if pagination is what you need. However, if you have multiple MySQL results you wish to organize and display “x” results per page, you’re on looking at the right thing. It is as simple as that. Pagination is really just web jargin used to shorten up “return results only displaying ‘x’ per page.”

So, I’m going to post the snippet and I’ll go into it a little bit, but I do believe that the comments explain pretty thoroughly. First the database structure we’re going to use ;)

CREATE TABLE `pagination` (
`id` BIGINT( 10 ) NOT NULL ,
`name` VARCHAR( 32 ) NOT NULL ,
`content` TEXT NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

And now.. The moment we’ve been waiting for… The actual pagination script! :)

<?php
/**
* Pagination Script by Dennis M.
* (C) 2009 Dennis M. All Rights Reserved.
*
* Primary purpose of this script is to teach
* people the art and concept of pagination
* and how to effectively create/use it.
* Please give credit to Dennis M. if you
* take anything directly from this script.
*
*/

// Connect to DB
mysql_connect("localhost","USER","PASS");
mysql_select_db("USER_DATABASE");

// Define results per page
$perPage = 1;

// Define page number in URL
$num = $_GET['no'];

// Define link starting point.
$linkno = 1;

// If no number given, default it.
if(!isset($num) OR !is_numeric($num)){
$num = 1;
}

// Multiply to see where we're at to show results :)
$currentLimit = $perPage*($num-1);

// Get how many pages we'll have total (for links)
$numPages = mysql_num_rows(mysql_query("SELECT * FROM pagination"))/$perPage;

$query = mysql_query("SELECT * FROM pagination ORDER BY id ASC LIMIT ".mysql_escape_string($currentLimit).",".mysql_escape_string($perPage).";");

// Fetch all the info
while($row = mysql_fetch_array($query)){
$title = stripslashes($row['name']);
$article = stripslashes($row['content']);
?>
<html>
<head>
<title>Pagination Test</title>
</head>
<body>
<h1><?php echo($title); ?></h1><br />
<p><?php echo($article); ?></p><br /><hr>
<?php
}
print "<p align=\"right\">";
if($perPage <= 2){
while($links < round($numPages)){
?>

<?php
$links++;
$linkno++;
}
} else {
while($links <= round($numPages)){
?>

<?php
$links++;
$linkno++;
}
}
?></p>
</body>
</html>

Now that’s all there really is to it. Basically how it works is it updates the SQL query depending on the page number (received from $_GET['no']). If none is defined, it reverts to the default and all goes accordingly!

Pagination Tutorial

The download link is above as usual! :) Enjoy

Regards,
Dennis M.

C++ Programming: Visual Windows

April 24th, 2009 admin No comments

I am primarily a programmer for *nix platforms and some cross compatibility for the DOS command prompt as many of you know. However, I also program Windows in the visual sense (how most end-users envision their product). So I’m going to write up a quick tutorial for you guys today!

I am compiling the example with Microsoft’s Visual C++. I am not normally an advocate for most things made by Microsoft, but in this case there is no doubt that this is the best compiler for compiling Windows programs. The best part about it is (unexpected, I know; it is Microsoft after all) that the compiler is FREE and comes with a very nice and clean GUI.

Now be mindful, the example has small functionality, but it is more or less the basis to ALL Windows programs! As we go through, we’ll explain the importance of each part. So let’s begin with the main file so you can see what’s going on.

main.cpp

/**
* Windows Programming Tutorial by Dennis M.
*
* main.cpp
*
*/

// Basic includes :D
#include <windows.h> // Win32 Lib
#include “menu.h” // Our menu – we’ll explain this later ;)
// more commonly named “resource.h,” but for
// explanation purposes this is easier :)

// Main WindowProcedure Definition
LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);
const char szClassName[] = “MicrosonicTestProgram”; // Our program’s name

int WINAPI
// Our main class to make the Window
WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArg,int WindowStyle)
{
// Pointer definitons
HWND hwnd;
MSG msgs;
WNDCLASSEX wcl;

// Standard window properties
wcl.hInstance = hThisInstance;
wcl.lpszClassName = szClassName;
wcl.lpfnWndProc = WindowProcedure;
wcl.style = CS_DBLCLKS;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
wcl.lpszMenuName = “MAIN_MENU”;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

if(!RegisterClassEx(&wcl)){
return 0;
}

hwnd = CreateWindowEx(
0,
szClassName,
“Microsonic.org Test Program”,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
HWND_DESKTOP,
LoadMenu(hThisInstance,”MAIN_MENU”),
hThisInstance,
NULL
);

// This is where we see the window.. ShowWindow()… duh!
ShowWindow(hwnd,WindowStyle);
while(GetMessage(&msgs,NULL,0,0)){
TranslateMessage(&msgs);
DispatchMessage(&msgs);
}
return msgs.wParam;
}

// Here we process all the commands etc.
LRESULT CALLBACK WindowProcedure(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
switch(msg){
// Process commands sent to the program
// In this case, from the menu items
case WM_COMMAND:
switch(wParam){
case MM_FILE_NEW:
MessageBox(hwnd,”MDI is more complex! Another tutorial soon perhaps on it! This is just the basics to Windows programming!\r\nSorry!”,
“Feature Not Available”,MB_OK);
return 0;
break;
case MM_FILE_EXIT:
PostQuitMessage(0);
return 0;
break;
case MM_HELP_ABOUT:
MessageBox(hwnd,”\tMicrosonic.org test program!\r\n\r\n\tFor more tutorials visit:\r\n\r\n\thttp://microsonic.org! \r\n”,
“Microsonic.org Test Program”,MB_OK);
return 0;
break;
case MM_HELP_VISIT:
ShellExecute(hwnd,”open”,”http://microsonic.org”,NULL,NULL,0);
return 0;
break;
}
break;
// If they hit the “X” button
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
// Default loop
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
break;
}
return 0;
}

Some basic points I’d like to touch upon. Since this is just the basics to the Window, I have not included MDI (allowing text, etc. through the new button) but, this is important for the generalization of the program. If you understand how this works, Windows programming becomes very similar to all other sorts of programming with the assistance of the MSDN Library. Now, realize that the structure file for the menu is never directly included into any C++ file, but rather automatically linked. Make sure you keep it this way and don’t make the mistake of including a .rc file. Also, as I peer through the code, it is important to realize that many of the function names are static. For the basics, all Windows programs should look as some sort of variation to this code simply by definition of a Windows program.

Now, let’s continue to see the header file. This purely holds definitions for the resource file holding the menu structure. If they are not defined, they will not work properly.

menu.h

/**
* Windows Programming Tutorial by Dennis M.
*
* menu.h
*
* Contains all our menu definitions
*
*/

// Give values to menu items
#define MM_FILE_NEW 2001
#define MM_FILE_EXIT 2002
#define MM_HELP_ABOUT 3001
#define MM_HELP_VISIT 3002

As you can see, each menu item is defined. These numbers are more or less arbitrary, you just want to make sure their definitions don’t conflict with each other or any other aspect of your program. I personally like to keep menu items grouped together, so I defined the “File” items in the 2000‘s and the “Help” items in the 3000‘s.

Finally, the structure of our menu. A resource file that is never really included.

menu.rc

/**
* Windows Programming Tutorial by Dennis M.
*
* menu.rc
*
* Resource file which contains the menu structure!
* To edit the file with Free Visual C++
* Right click and “View Code”
* Again, more commonly named “resource.rc”
*
*/
// Menu definitions
#include “menu.h”

// Should be able to get the hang of the menu ;)
MAIN_MENU MENU
BEGIN
POPUP “&File”,
BEGIN
// Format: MENUITEM “Title”, COMMAND_TO_SEND
MENUITEM “N&ew”, MM_FILE_NEW
MENUITEM SEPARATOR
MENUITEM “E&xit”, MM_FILE_EXIT
END
POPUP “&Help”
BEGIN
MENUITEM “A&bout”, MM_HELP_ABOUT
MENUITEM SEPARATOR
MENUITEM “G&oto Microsonic.org”, MM_HELP_VISIT
END
END

The structure is fairly straight forward, so I can probably leave it without much explanation. The only thing I would like to say is that you should realize how usable menu items are presented.
MENUITEM “Display Text”, DEFINED_FUNCTION.
The defined function is what is sent to the main loop of the program and is processed in the “switch.” Just remember this when you’re creating your programs!

As usual, I will provide complete source WITH the VC++9 Project file!

If you choose to make your own project, please make sure you go to the “General” tab and create an empty project. Compiler options in other Visual C++ presets do not work properly for many reasons. A major error one could run into (if using another setting) is compiling UNICODE which would break “const char szClassName[]” by definiton. You would then have to declare it as _T string.

Simple Win32 API Tutorial

Regards,
Dennis M.

It’s Here: PHP + Password + Salt Tutorial

April 5th, 2009 admin 20 comments

Well, I’ve finally gotten to it! Here’s that long promised tutorial for you guys! I hope it helps. I won’t do a lot of explaining in the post seeing as most of it I think I made pretty clear in the code itself but I’ll explain the function of each document :)

I’ve also prepare the whole tutorial in a convenient download link for those who wish to just download it. This may be the most efficient way to look at the code until I fix the wordpress theme to actually include a worthwhile PHP code in post function XD. This looks ugly no doubt. So you can download that at:
PHP Password+Salt Encryption Tutorial – Files Download (Also will be provided at the end of the post!)

First, here’s the config.php. This basically starts our session (so users can log in – it’s the first file included in the operative page: only index so it carries over. Would also need to be the first file included in all other documents unless they begin with “session_start();” as well).

<?php
// Start our sessions
session_start();

// Just some definitions of DB info
define("DATABASE","YOUR_TABLE");
define("DBUSER","YOUR_USERNAME");
define("DBPASS","YOUR_PASSWORD");
define("DBHOST","localhost");

// Script security
define("IS_SCRIPT",true);

?> 

Next, we have our index.php. No true functionality in this script, it’s basically just a simple file to make all the functions work.

<?php
/**
 * Salt Encryption Tutorial by Dennis McWherter
 *
 * (C) 2009 Dennis McWherter. All Rights Reserved.
 *
 * This is where all of our functions are. Yes a lot of these
 * Some of this stuff is extra nonsense, but makes life a lot
 * more difficult for hackers.
 *
 */
require_once("config.php");
require_once("functions.php");$login = new Login;if(!isset($_GET['page'])){
  $_GET['page'] = "index";
}switch($_GET['page']){
  default:
    if(!$_SESSION['username']){      print "<form name="login" method="post" action="?page=login">
    <p>User: <input type="text" name="user" /></p>
    <p>Pass: <input type="password" name="pass" /></p>
    <p><input type="submit" value="login" /></p>
    <p>Register</p></form>";
      exit;
    } else {      print "Hello ".$_SESSION['username'].",<br /><br />Welcome to a random test site!
    <br /><br />Your password is safe here ;) <br /><br />logout";
      exit;
    }
  break;
  case 'register':
    if(!isset($_POST['user']) OR !isset($_POST['pass'])){
      print "<p>All fields are required! (If they are not filled out, you will be
    returned to this page!)</p><br /><br />    <form name="reg" method="post" action="?page=register">
    <p>User: <input type=text" name="user" /></p>
    <p>Pass: <input type="password" name="pass" /></p>
    <p><input type="submit" value="register" /></p>
    </form>";
      exit;    } else {
      if(!$login->register($_POST['user'],$_POST['pass'])){
        print "Login failed: Username already in use!";
        exit;
      } else {
        print "Login successful! You can now login!";        exit;
      }
    }
  break;
  case 'login':
    if(!isset($_POST['user']) OR !isset($_POST['pass'])){
      $_GET['page'] = "index";
    } else {      $login->login($_POST['user'],$_POST['pass']);
    }
  break;
  case 'logout':
    if(!isset($_SESSION['username'])){
      print "User is not logged in!";
    } else {      if(session_destroy()){
        print "User logged out successfully!";
      } else {
        print "User could not be logged out!";
      }
    }
  break;}

?> 

Now, here’s the extensive script which does it all! It is more or less thoroughly documented, so no worries there. Should be pretty well explained. Here goes:

<?php
/**
 * Salt Encryption Tutorial by Dennis McWherter
 *
 * (C) 2009 Dennis McWherter. All Rights Reserved.
 *
 * This is where all of our functions are. Yes a lot of these
 * Some of this stuff is extra nonsense, but makes life a lot
 * more difficult for hackers.
 *
 */
// Script security :)
if(!defined("IS_SCRIPT")){
  print "Unauthorized access";
  exit;
}class Login
{  /**
   * Constructor :D
   *
   */
  function __construct(){
    mysql_connect(DBHOST,DBUSER,DBPASS);
    mysql_select_db(DATABASE);
  }  /**
   * Register function :D
   *
   */
  function register($user,$pass){
    // Simple checks.. umm. Yeah let's make sure user doesn't exist XD
    $check = mysql_query("SELECT * FROM users WHERE user='".mysql_escape_string($user)."'");
    if(mysql_num_rows($check) != 0){
      return false;
    }    // Let's begin with making our first and second salt character set
      // This is our first set of possible salt characters. Shuffle so always different all aspects
    $set1 = str_shuffle("!@#$%^&*()_+=-';:,<.>126AaBbJjKkLlSdDsQwWeErqRtTyY");
      // Second set. Same thing, different characters though :D
    $set2 = str_shuffle("1234567890`~ZxzxCcVvBb?[]{}pP");    // Now the loops to actually make the salt characters
    // We'll be using the rand(); function give us random chars from the shuffled sets
    // The for loops are fairly simple.
    // Salt1 = 12 char
    // Salt2 = 10 char
    for($i=0;$i<12;$i++){
      $salt1 .= $set1[rand() % strlen($set1)-.04];
    }    for($i=0;$i<10;$i++){
      $salt2 .= $set2[rand() % strlen($set2)-.07];
    }    // Now let's generate a pattern. We'll have only about 4 combinations.
    // For time sake we'll only do a few simple ones.
    $part[1] = "{salt1}";
    $part[2] = "{salt2}";
    $part[3] = "{pass}";
    $psort   = array_rand($part,3);
    $pattern = $part[$psort[0]].".".$part[$psort[1]].".".$part[$psort[2]];    // Now for pass
    $grep = array("/{salt1}/","/{salt2}/","/{pass}/"); // Identify pattern
    $repl = array($salt1,$salt2,$pass); // Make pattern real    // Now replace the pattern with actual values XD
    $sendpass = preg_replace($grep,$repl,$pattern);    // Send all to DB
    $query = "INSERT INTO users (`id`,`user`,`password`,`salt1`,`salt2`,`pattern`) VALUES
    (NULL, '".mysql_escape_string($user)."',
    '".md5($sendpass)."', '".mysql_escape_string($salt1)."',
    '".mysql_escape_string($salt2)."', '".mysql_escape_string($pattern)."')";
    if(!mysql_query($query)){      print "DB Connection failed: ".mysql_error();
      return false;
    }
    return true;
  }  /**
   * Login Function
   *
   */
  function login($user,$pass){
    // Grab info by username since usernames are unique anyway...
    $query = "SELECT * FROM users WHERE user='".mysql_escape_string($user)."' LIMIT 1;";
    if(!mysql_query($query)){      print "DB Connection Failed: ".mysql_error();
      return false;
    }
    $info  = mysql_fetch_assoc(mysql_query($query));
    // Use the grep and replace arrays again to replace information from pattern!
    $grep = array("/{salt1}/","/{salt2}/","/{pass}/"); // Identify pattern
    $repl = array($info['salt1'],$info['salt2'],$pass); // Make pattern real    $pwd  = preg_replace($grep,$repl,$info['pattern']); // Generate password how it should be.    // Now let's make sure the user is properly identifying!
    if(md5($pwd) != $info['password']){
      print "Incorrect password!";
      unset($info);
      return false;
    }    // All checks out... Let's create session data and give a success msg.. We're just about done
    // anyway ;)     $_SESSION['username'] = $user;
    print "You've logged in successfully! Please return home";    // Delete all info in the $info var
    unset($info);
    return true;
  }
}
?> 

Oh yeah, and can’t forget the database structure! Run this query to duplicate the database :)

CREATE TABLE `users` (
`id` BIGINT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`user` VARCHAR( 32 ) NOT NULL ,
`password` VARCHAR( 32 ) NOT NULL ,
`salt1` VARCHAR( 12 ) NOT NULL ,
`salt2` VARCHAR( 10 ) NOT NULL ,
`pattern` VARCHAR( 22 ) NOT NULL
) ENGINE = MYISAM ;

Regards,
Dennis M.

Again, that download link is: PHP Password+Salt Encryption Tutorial – Files Download

Simple $_SESSION Tutorial

March 12th, 2009 admin No comments

In this tutorial, we’ll speak about the $_SESSION tool and how it can be effective in securely storing data!

What are sessions good for:

  • Storing Login Information
  • Storing User Information
  • Checking if User is Logged In

The list goes on but those are just a few possibilites.

Today, I’m going to write an example on how to use them and set a time when to automatically log the user out!

First, we’ll make the init.php. This will hold our “session_start();” variable (located at the beginning – this file must be included in all other files in which you want sessions to carry over)

<?php
/**
* Simple Sessions Script by Dennis M.
*
* File: init.php
* Desc: To do most of the session handling
*
* Author: Dennis M.
*
*/
session_start(); // Must come first so this works
// Let's see if the user is logged in!
if(isset($_SESSION['user'])){
// Apparently the user is logged in. So let's check if the session has expired. We'll set it to 5min expiration if idle (300 seconds)
if(time() &gt;= $_SESSION['time']+300){
session_destroy();
print "Your session has expired!";
exit;
}
$_SESSION['time'] = time(); // User passed the testing! :D Let's reset their time.
}
define("SCRIPT",true); // Simple definition to allow security access to our functions.php :)

?>

Now that we have created that file, we can create the functions which will make this all work properly. We’ll call this “functions.php”
<?php
/**
* Simple Sessions Script by Dennis M.
*
* File: functions.php
* Desc: Make the sessions work! :)
*
* Author: Dennis M.
*
*/
// This is what that init.php definition was for! ;)
if(!defined("SCRIPT")){
print "Unauthorized access!";
exit;
}

class Login_Base
{
/**
* Our constructor!
*
*/
function __construct(){
// Just our MySQL Info ;) - DB structure is at the end of the post!
mysql_connect("localhost","USER","PASS");
mysql_select_db("DB_NAME");
// Almost forgot. Define a prefix for the db!
$prefix = "sestut";
}
/**
* Let's Register the user!
*
*/
function register($user,$pass){
// Let's check if the user exists. If so, let's not overwrite :) plz and thanks
$query = mysql_query("SELECT * FROM ".$prefix."_users WHERE user='".mysql_escape_string($user)."'");
if(mysql_num_rows($query) > 0){
return false;
}
// Seems all is well. Let's make the user...
$pass = md5($pass); // Simple encryption.. Hold the salt please...
$query = mysql_query("INSERT INTO ".$prefix."_users (`id`, `user`, `pass`) VALUES (NULL, '".mysql_escape_string($user)."', '".$pass."')");
if(!$query){
print "MySQL Error: ".mysql_error();
return false;
}
return true;
}
/**
* Now login :)
*
*/
function login($user,$pass){
// Check for everything now!
$query = mysql_query("SELECT * FROM ".$prefix."_users WHERE user='".mysql_escape_string($user)."' AND password='".md5($pass)."'");
if(mysql_num_rows($query) == 0){
print "Invalid login credentials!";
return false;
}
// Passed the test :D Let's set everything...
$_SESSION['user'] = $user;
$_SESSION['time'] = time(); // This is important for expiration handling ;)
return true;
}
}

?>

Our functions are now fixed up nicely. Time for the index page! We’re not going to be diving into SEO friendly URLs for this one, so we’re going to use a standard ?page=ACTION style link. But we’ll make due ;)

<?php
/**
* Simple Sessions Script by Dennis M.
*
* File: index.php
* Desc: Use what was created earlier!
*
* Author: Dennis M.
*
*/
include_once("init.php"); // VERY Important that this is included FIRST! (BEFORE any other code - not including comments)
include_once("functions.php"); // Our functions
$login = new Login_Base; // Define a variable to point to the class and functions...// Define default page for users not logged in or if the page is not directed to registration
if(!isset($_SESSION['user']) && $_GET['page'] != "register" && !isset($_POST['form'])){
print "<form name=\"login\" method=\"post\" action=\"?page=login\">
<p>Username: <input type=\"text\" name=\"user\" /></p>
<p>Password: <input type=\"password\" name=\"pass\" /></p>
<p><input type=\"submit\" value=\"login\" /></p>
<input type=\"hidden\" name=\"form\" value=\"true\" />
</form>
<p>Register Now!</p>";
exit;
}
// Default everything out :)
if(!isset($_GET['page'])){
$_GET['page'] = "index";
}
switch(strtolower($_GET['page'])){
default:
print "<p>The login has been successful!<br /><br />
Your username is: ".$_SESSION['username']."<br /><br />
Please proceed with the following:<br />
Test page 2 (Separate page to show that it carries)<br />
Logout</p>";
break;
case 'logout':
if(session_destroy()){
print "Successfully logged out!";
exit;
} else {
print "There was an error logging out!";
exit;
}
break;
case 'register':
if($_GET['act'] != "go"){
print "<form name=\"register\" method=\"post\" action=\"?page=register&act=go\">
<p>Username: <input type=\"text\" name=\"user\" /></p>
<p>Password: <input type=\"password\" name=\"pass\" /></p>
<p><input type=\"submit\" value=\"Register\" /></p>
</form>";
} else {
if($login->register($_POST['user'],$_POST['pass'])){
print "Registration successful! You can now login!";
} else {
print "Registration failed!";
}
}
break;
case 'login':
if($login->login($_POST['user'],$_POST['pass'])){
print "Login successful! Please go back home";
exit;
} else {
print "Login failed!";
exit;
}
break;
}
?>

Now one final test to make sure everything is working properly. A simple “test.php” should do! Just another file to show sessions are being properly handled.

<?php
/**
* Simple Sessions Script by Dennis M.
*
* File: test.php
* Desc: Wrapping things up now. Name implies it all :)
*
* Author: Dennis M.
*
*/
include_once("init.php"); // Again very important to include first

// Check if user logged in..if(!isset($_SESSION['user'])){
print "Uh-oh, you're not logged in! Try going here to login!";
exit;
}

print "Great, you're logged in!<br /><br />Username: ".$_SESSION['user']."<br /><br />Return to index";
?>

As mentioned earlier, I’d give the database structure as well. What I use by default is the name ‘sestut_user’ for the table but you can do whatever you like! (Provided that you properly modify the code to do so)
CREATE TABLE `users` (
`id` BIGINT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`user` VARCHAR( 32 ) NOT NULL ,
`password` VARCHAR( 32 ) NOT NULL
) ENGINE = MYISAM ;

Regards,
Dennis M.