我正在尝试将在php文件中分配的会话变量携带到一个html文件但是什么都没有显示..我已经尝试了很多方法来分配它并将会话变量携带到我的html页面但是我无法这样做..请帮我解决这个问题。如果我出错了,请原谅.. !!
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
<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>
答案 0 :(得分:0)
<?php
session_start();
?>
需要处于每个页面的最开始,而不是在它之前。
答案 1 :(得分:0)
<?php session_start(); ?>
在页面的第一行写下这一行
另一件事不能在html页面中运行的php必须使用php