简体   繁体   中英

How can I send user session from one page to another till destroyed in php and mysql

I have session page with these code

session_start();

if (!isset($_SESSION['id'])){
header('location:order.php');
}

$ses_id = $_SESSION['id'];

I included it into my login page (order.php)

<?php include('session.php'); ?>

Here is the login scripts and functions

$username = clean($_POST['username']);
$password =  md5($_POST['password']);
$apollos=$username;
$query=Login($username,$password);
$count = mysql_num_rows($query);
$row = mysql_fetch_array($query);
$phone=$row['Contact_Number'];

DeleteActivation($username);

if ($count > 0) {
    $_SESSION['id'] = $row['memberID'];

    UserPin($username,$pin,$member);
    $From='eFarms';
    $Message='Your User Login Pin from St. Apollos eFarms is '.$pin;

    die("<script>location.href = 'login_sms.php'</script>");
    session_write_close();
} else {
    session_write_close();
}

Here is my Pin Validation Page

<?php include('header.php'); ?>
pin = clean($_POST['pin']);


$query=CheckPin($username,$pin,$member);

$count = mysql_num_rows($query);
$row = mysql_fetch_array($query)

if ($count > 0) {
    $_SESSION['id'] = $row['memberID'];
    die("<script>location.href = 'user_home.php'</script>");
    session_write_close();
} else {
    session_write_close();
}

Someone should please examine these codes, correct and show me how to receive the session to the USer Home Page as Username.

Before session start you have to check the session is already started or not like below in each script or in common script file.

if (!isset($_SESSION)) {
    session_start();
}

Edited:

the above condition is not needed as it is checking internally as descripe in the documentation - http://php.net/manual/en/function.session-start.php

session_start();

First, as provided by others, ur using very bad and insecure method ! Try to use PDO which is much easier (when u understand how it work) and it's much more secure !

Second, ur coding is not so clean, I think that's why u can't find the problem urself !

And finally, I think ur missing :

session_start();

in some part of ur code !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM