use session create member log in wih mysql

Sandy | Full stack Web developer

Now, we look at a more substantial example using session control.Use session create your member log in system with mysql

now your could create a page named:authmain.php

here is the code:


if (isset($_POST[‘userid’]) && isset($_POST[‘password’]))
// if the user has just tried to log in
$userid = $_POST[‘userid’];
$password = $_POST[‘password’];

$db_conn = new mysqli(‘localhost’, ‘webauth’, ‘webauth’, ‘auth’);

if (mysqli_connect_errno()) {
echo ‘Connection to database failed:’.mysqli_connect_error();

$query = “select count(*) from authorized_users where
name = ‘”.$name.”‘ and
password = sha1(‘”.$password.”‘)”;

$result = $db_conn->query($query);
if ($result->num_rows >0 )
// if they are in the database register the user id
$_SESSION[‘valid_user’] = $userid;
<h1>Home page</h1>
if (isset($_SESSION[‘valid_user’]))
echo ‘You are logged in as: ‘.$_SESSION[‘valid_user’].’ <br />’;
echo ‘<a href=”logout.php”>Log out</a><br />’;
if (isset($userid))
// if they’ve tried and failed to log in
echo ‘Could…

View original post 73 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s