How To Login And Logout With Session In PHP

this is a simple tutorial for beginners by the way this is also a good way to login and logout
lets make the index.php
login page - login.php
 0){
  session_start();
  $_SESSION['member_id']=$row['member_id'];
  header('location:home.php');
  }else{
  header('location:index.php');
  }
}
?>
SQL database connect - conn.php sql database - database.sql
-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 09, 2012 at 12:40 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `database`
--

-- --------------------------------------------------------

--
-- Table structure for table `members`
--

CREATE TABLE IF NOT EXISTS `members` (
  `member_id` int(11) NOT NULL AUTO_INCREMENT,
  `UserName` varchar(200) NOT NULL,
  `Password` varchar(200) NOT NULL,
  `FirstName` varchar(200) NOT NULL,
  `LastName` varchar(200) NOT NULL,
  PRIMARY KEY (`member_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `members`
--

INSERT INTO `members` (`member_id`, `UserName`, `Password`, `FirstName`, `LastName`) VALUES
(1, 'js', 'js', 'john', 'smith'),
(2, 'jk', 'jk', 'john kevin', 'lorayna'),
(5, 'admin', 'admin', 'john', 'smith');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

home - home.php login - login.php
 0){
  session_start();
  $_SESSION['member_id']=$row['member_id'];
  header('location:home.php');
  }else{
  header('location:index.php');
  }
}
?>
logout - logout.php done hope your problems solved with this

Post a Comment

Note: Only a member of this blog may post a comment.