简体   繁体   English

无法将会话变量执行到下一页。

[英]Not able to carry out the session variable to next page..!

I am trying carry the session variable assigned in php file to a html file but nothing is displayed..i have tried out many ways to assign it and carry the session variable to my html page but am unable to do so..please help me out of this..i beg you pardon if i have gone wrong..!! 我正在尝试将在php文件中分配的会话变量携带到html文件中,但什么都没有显示。.我尝试了多种方法来分配它,并将会话变量携带到我的html页面中,但是无法这样做。出于这个..如果我错了,我请你原谅.. !!

php PHP

         <?php
                session_start();
                require_once 'DB_Functions.php';
                $db = new DB_Functions();

                // json response array
                $response = array("error" => false);
                if (!empty($_POST['salutation']) && !empty($_POST['fname']) && !empty($_POST['lname']) && !empty($_POST['dob']) && !empty($_POST['mobile']) && !empty($_POST['country']) && !empty($_POST['state']) && !empty($_POST['city']) && !empty($_POST['pin'])){
                        /*
                        if required include seperate validation
                        for some fields which require validation
                        */
                        // receiving the post params
                        $salutation = ($_POST['salutation']);
                        $fname = trim($_POST['fname']);
                        $lname = trim($_POST['lname']);
                        $dob = trim($_POST['dob']);
                       /* $email = trim($_POST['email']);
                        $password = $_POST['password'];*/
                        $mobile = trim($_POST['mobile']);
                        $country = trim($_POST['country']);
                        $state = trim($_POST['state']);
                        $city = trim($_POST['city']);
                        $pin = trim($_POST['pin']);

                        /*
                        validation process
                        starts from here
                        */

                        // validate your email address

                       /* if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
                                //validate your password
                                if(strlen($password) >= 6){*/
                                        //validate your mobile
                                        //$mobile="/^[1-9]*$/";
                                        if(strlen($mobile) == 10){
                                                 //Check for valid email address
                                                 /*if ($db->isUserExisted($email)) {
                                                                        // user already existed
                                                                        $response["error"] = true;
                                                                        $response["error_msg"] = "User already existed with " . $email;
                                                                        echo json_encode($response);
                                                                }*/
                                                                if($db->isMobileNumberExisted($mobile)) {
                                                                                //user already existed
                                                                                $response["error"] = true;
                                                                                $response["error_msg"] = "user already existed with" . $mobile;
                                                                                echo json_encode($response);
                                                                }else{  
                                                                        // create a new user
                                                                        $user = $db->storeUser($salutation, $fname, $lname, $dob, $mobile, $country, $state, $city, $pin);
                                                                        if ($user) {
                                                                                // user stored successfully
                                                                                $response["error"] = false;

/*here is the session variable
to be carried to next page
*/
                                                                                $_SESSION["user"]["vault_no"] = $user["vault_no"];
                                                                                echo json_encode($response);
                                                                        } else {
                                                                                // user failed to store
                                                                                $response["error"] = true;
                                                                                $response["error_msg"] = "Unknown error occurred in registration!";
                                                                                echo json_encode($response);
                                                                        }
                                                                }

                                        }else{
                                                //invalid mobile number
                                                $response["error"] = true;
                                                $response["error_msg"] = "PLEASE ENTER VALID MOBILE NUMBER!";
                                                echo json_encode($response);
                                        }
                             /*   }else{
                                        //min of 6-charecters
                                        $response["error"] = true;
                                        $response["error_msg"] = "PASSWORD MUST BE OF MINIMUM 6-CHARACTERS!";
                                        echo json_encode($response);
                                }
                        }else{
                                // invalid email address
                                $response["error"] = true;
                                $response["error_msg"] = "invalid email address";
                                echo json_encode($response);
                        }*/
                }else{
                        //missing the required fields
                        $response["error"] = true;
                        $response["error_msg"] = "Please fill all the required parameters!";
                        echo json_encode($response);
                }

        ?> 

html HTML

    <div>
                        <?php
                        session_start();
                        echo "your vault number is" . "-" . $_SESSION["user"]["vault_no"];
                        ?>
                        </div>
                        <div>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <ul>
                        <h2 style="text-center"><li>Above is your 15 digit vault no, please do not share/Disclose to anyone.</li></h2>
                        <h2 style="text-center"><li>Please use this 15 digit no to modify your Vault or SignIn in to Miisky.</li></h2>

                        </ul>

                        </div>
<?php
session_start();
?>

Needs to be at the very start of every page and nothing before it. 需要位于每个页面的开始,并且之前没有内容。

<?php session_start(); ?> 

write this line on first line of the page 将此行写在页面的第一行

and another thing php not run in html page must extantion php 和另一件事PHP不能在HTML页面中运行必须引爆PHP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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