Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未在live server中传递会话变量_Javascript_Php_Html_Session - Fatal编程技术网

Javascript 未在live server中传递会话变量

Javascript 未在live server中传递会话变量,javascript,php,html,session,Javascript,Php,Html,Session,我已经在php中尝试了一些用于用户注册的代码。整个代码在本地服务器上运行良好,但在live server中,每个php代码都会被执行,但不会显示会话变量,但在本地服务器中,会话变量会被正确传递和显示 DB_Function.php public function storeUser($salutation, $fname, $lname, $dob, $mobile, $country, $state, $city, $pin){ try { //$hash = md

我已经在php中尝试了一些用于用户注册的代码。整个代码在本地服务器上运行良好,但在live server中,每个php代码都会被执行,但不会显示会话变量,但在本地服务器中,会话变量会被正确传递和显示

DB_Function.php

public function storeUser($salutation, $fname, $lname, $dob, $mobile, $country, $state, $city, $pin){  
    try {
        //$hash = md5($password);
        $characters = '0123456789';
            $uuid = '';
            $random_string_length = 5;
        for ($i = 0; $i < $random_string_length; $i++) {
            $uuid .= $characters[rand(0, strlen($characters) - 1)];
        }
        $fullname = $fname . " " . $lname;
        $vault_no = $salutation . "" . $country . "" . $pin . "" . $uuid;
        $sql = "INSERT INTO users(salutation, fname, lname, fullname, dob, mobile, country, state, city, pin, unique_id, vault_no, created_at) VALUES ('$salutation', '$fname', '$lname', '$fullname', '$dob', '$mobile', '$country', '$state', '$city', '$pin', '$uuid', '$vault_no', NOW())";
        $dbh = $this->db->prepare($sql);

        /*execute the insert query in 
        get the user details return
        */
        if($dbh->execute()){
            // get user details
            $sql = "SELECT * FROM users WHERE mobile = '$mobile' LIMIT 1";
            $dbh = $this->db->prepare($sql);
            $result = $dbh->execute();
            $rows = $dbh->fetch();
            $n = count($rows);
            if($n){
                return $rows;
            }
        }
    }
    catch (Exception $e) {
        die('Error accessing database: ' . $e->getMessage());
    }
    return false;
}
<?php
session_start();
 ?>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>MiiSKy | Register</title>
    <script type="text/javascript" src="jquery_source.js"></script>
    <script type="text/javascript" src = "register.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">
    <!--<link href="css/plugins/iCheck/custom.css" rel="stylesheet">-->
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <!--<script src='https://www.google.com/recaptcha/api.js'></script>-->

    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">

    <link href="css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <!--Dropzone-->
    <link href="css/plugins/dropzone/basic.css" rel="stylesheet">
    <link href="css/plugins/dropzone/dropzone.css" rel="stylesheet">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>



</head>

<body class="gray-bg">

    <div class="middle-box text-center loginscreen   animated fadeInDown">
        <div>
            <div>

                <!--<h3 class="logo-name">MiiSky</h3>-->
                <img src="img/landing/mii-logo.png">
            </div>
            <!--<h3>Register to MiiSky</h3>-->
            <p>Create your vault to see it in action.</p>
            <form id = "form" name = "form" class="validate-form" method="POST" action="formprofile.php" autocomplete = "off" >
 <?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;
                                                                        $_SESSION["fullname"] = $user["fullname"];
                                                                        $_SESSION["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);
        }

?>
register.php

public function storeUser($salutation, $fname, $lname, $dob, $mobile, $country, $state, $city, $pin){  
    try {
        //$hash = md5($password);
        $characters = '0123456789';
            $uuid = '';
            $random_string_length = 5;
        for ($i = 0; $i < $random_string_length; $i++) {
            $uuid .= $characters[rand(0, strlen($characters) - 1)];
        }
        $fullname = $fname . " " . $lname;
        $vault_no = $salutation . "" . $country . "" . $pin . "" . $uuid;
        $sql = "INSERT INTO users(salutation, fname, lname, fullname, dob, mobile, country, state, city, pin, unique_id, vault_no, created_at) VALUES ('$salutation', '$fname', '$lname', '$fullname', '$dob', '$mobile', '$country', '$state', '$city', '$pin', '$uuid', '$vault_no', NOW())";
        $dbh = $this->db->prepare($sql);

        /*execute the insert query in 
        get the user details return
        */
        if($dbh->execute()){
            // get user details
            $sql = "SELECT * FROM users WHERE mobile = '$mobile' LIMIT 1";
            $dbh = $this->db->prepare($sql);
            $result = $dbh->execute();
            $rows = $dbh->fetch();
            $n = count($rows);
            if($n){
                return $rows;
            }
        }
    }
    catch (Exception $e) {
        die('Error accessing database: ' . $e->getMessage());
    }
    return false;
}
<?php
session_start();
 ?>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>MiiSKy | Register</title>
    <script type="text/javascript" src="jquery_source.js"></script>
    <script type="text/javascript" src = "register.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">
    <!--<link href="css/plugins/iCheck/custom.css" rel="stylesheet">-->
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <!--<script src='https://www.google.com/recaptcha/api.js'></script>-->

    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">

    <link href="css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <!--Dropzone-->
    <link href="css/plugins/dropzone/basic.css" rel="stylesheet">
    <link href="css/plugins/dropzone/dropzone.css" rel="stylesheet">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>



</head>

<body class="gray-bg">

    <div class="middle-box text-center loginscreen   animated fadeInDown">
        <div>
            <div>

                <!--<h3 class="logo-name">MiiSky</h3>-->
                <img src="img/landing/mii-logo.png">
            </div>
            <!--<h3>Register to MiiSky</h3>-->
            <p>Create your vault to see it in action.</p>
            <form id = "form" name = "form" class="validate-form" method="POST" action="formprofile.php" autocomplete = "off" >
 <?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;
                                                                        $_SESSION["fullname"] = $user["fullname"];
                                                                        $_SESSION["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);
        }

?>

form.php代码片段

  <?php
session_start();
?>
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>MiiSky | Dashboard</title>
    <script type="text/javascript" src="jquery_source"></script>
    <script type="text/javascript" src = "form_profile.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">

    <!-- Toastr style -->
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">

    <!-- Gritter -->
    <link href="js/plugins/gritter/jquery.gritter.css" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

</head>

<body>
    <div id="wrapper">
        <nav class="navbar-default navbar-static-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav metismenu" id="side-menu">
                    <li class="nav-header">
                        <div class="dropdown profile-element">
                            <!--<span>
                                <img alt="image" class="img-circle" src="img/sunil1.jpg" />
                            </span>-->
                            <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">
                 /*here is use of session variable*/
                    <?php
                    echo $_SESSION["fullname"];
                    ?></strong>
                             </span>
                              <!--<span class="text-muted text-xs block">Android Developer <b class="caret"></b></span>--> </span> </a>
                            <ul class="dropdown-menu animated fadeInRight m-t-xs">
                                <li><a href="#">Profile</a></li>
                                <li><a href="#">Contacts</a></li>
                                <li><a href="#">Mailbox</a></li>
                                <li class="divider"></li>
                                <li><a href="sign_out.php">Sign out</a></li>
                            </ul>
                        </div>
                        <div class="logo-element">
                            MiiSky
                        </div>
                    </li>

                    <li>
                    <a href=""><i class="fa fa-user"></i> <span class="nav-label">Profile Vault</span><span class="fa arrow"></span></a>


                </li>



                </ul>

            </div>
        </nav>

        <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
        <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
            <form role="search" class="navbar-form-custom" action="search_results.html">
                <div class="form-group">
                    <input type="text" class="form-control" name="top-search" id="top-search">
                </div>
            </form>
        </div>
            <ul class="nav navbar-top-links navbar-right">
                <li>
                    <span class="m-r-sm text-muted welcome-message">Welcome to MiiSky</span>
                </li>
                <li class="dropdown">



                <li>
                    <a href="signin.html">
                        <i class="fa fa-sign-out"></i> Sign Out
                    </a>
                </li>
                <!--<li>
                    <a class="right-sidebar-toggle">
                        <i class="fa fa-tasks"></i>
                    </a>
                </li>-->
            </ul>

        </nav>
        <br><div style="font-size:30px; text-align:center;">
                   /*here is use of session variable*/
                    <?php
                    echo "<h1>Your Vault Number is generated and will be sent to your Mobile shortly.<br></h1>"  . $_SESSION["vault_no"];
                    ?>
                    </div>           

米斯基仪表盘
    米斯基
  • 欢迎来到米斯基

/*下面是会话变量的用法*/
会话_start()函数必须是文档中的第一件事。在任何HTML标记之前。 试试这个:


在声明会话变量之前,您有足够的空间

  <?php
session_start();
?>


注意
之前的空格,您已将
全名
保存为
$\u会话[“用户”][“全名”]

$_SESSION["user"]["fullname"] = $user["fullname"];
但你是这样回应的:

echo $_SESSION["fullname"];
将其修复为回显正确的一个:

echo $_SESSION["user"]["fullname"];

注意:您可以使用附加的检查
if(isset($\u SESSION[“user”][“fullname”])
,以便在未实际设置时不会出现错误。但是,在使用正确的变量/键之前,这不会解决任何问题。

您是否也在form.php页面上启动了会话?您必须在使用会话变量的每个页面上使用
session\u start()
;因此,如果在会话数组中没有看到任何内容,这意味着没有创建用户。我在这里没有看到任何错误,并且注释和答案足以解决此问题。你可能想看看。如果这也不能解决您的问题,请联系您的主机提供商。您需要制作
php.ini
文件,并将这一行添加到此文件中:
session.save_path=“/temp/php_sessions”
。您需要创建文件夹
temp
,然后将其他
php\u会话
文件夹创建到当前的
temp
文件夹中。是的,先生完成了更改,但遗憾的是没有工作。。!!注意:这仅适用于PHP手册中所述的基于cookie的会话-“要使用基于cookie的会话,必须先调用session_start(),然后才能将任何内容输出到浏览器。”-soo….先生,如果我出错了,您可以给我加上guid吗。。!!好的……先生,我试试。。!!注意:这仅适用于PHP手册中所述的基于cookie的会话-“要使用基于cookie的会话,必须先调用session_start(),然后才能将任何内容输出到浏览器。”-先生..我发现您的答案有效。。!!先生,我已经编辑了我的代码。实际上,那是一个旧代码,现在我已经如上所述更改了它。。。。!!!根据你的建议,我已经删除了我的答案。。!!请检查代码…任何建议都可以接受。。!!谢谢,您也可以为您的
$db->storeUser()
函数添加代码吗?或者至少是此函数返回的
$user
数组的示例。给您,先生。。。!!