Jump to content

Login Session Help


princeofpersia

Recommended Posts

Hi guys, I have a loggin page which works fine except it doesnt pass the session, could someone help me to see what mistake im making?

once users login they will be diverted to another page where is their profile page, i have echoed the session in member page but it doesnt read it.

 

i have attached both codes (member page and login page) below, thanks in advance for your help

 

 

code is below:

login page code:

 

 

<?php

//connect to database 
include '../include/db.php';

//we start a session here to help us pass the user login variable to other pages of the webs application while user is logged in.
session_start();

//php login

// if post has been successfully sent, do the action below

if ($_POST['login']){

// get data from form fields
$email=strip_tags($_POST['email']);
$password=strip_tags($_POST['password']);


// check if email (username) and password have been inserted, if not show an error

if($email == "" || $password == "")
echo "Please enter your email address and postcode";
else 
{

//check if email exists

$checkemail=mysql_query("SELECT * FROM member WHERE EmailAddress='$email'");


//if exists we get the information from database
if 

($getrows=mysql_num_rows($checkemail)>=1){

while ($row=mysql_fetch_array($checkemail))
{
$myemail=$row['EmailAddress'];
$mypassword=$row['Password'];
}

//convert the password to md5

$pass=md5($password);



//now we check if entered email and password match our database record
if ($myemail==$email && $mypassword==$pass)

{

$_SESSION['emailaddress']=$myemail;

//update the loggedin to 1 so we users go to next page, our website will compare if users is logged in or not
$update=mysql_query("UPDATE member SET loggedin='1' WHERE EmailAddress='$email'");

//if details exist we get the users first name  our database to pass this information along with our sessions
$getuser=mysql_query ("SELECT * FROM member WHERE EmailAddress='$email'");
while($row=mysql_fetch_array($getuser))

{
$firstname=$row['FirstName'];


}
echo "Welcome $firstname, <a href='profile.php'>Click here</a> to be directed to your profile";
}

}
else 

{
echo "This user doesn't exists";
}

}
}



?>



 

and this is the member page so far

 

<?php
//connect to database 
include '../include/db.php';

//we start a session here to help us pass the user login variable to other pages of the webs application while user is logged in.
session_start();
echo "Welcome ".$_SESSION['emailaddress']."";
?>




Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.