Cas*_*sey 1 php header session-variables
用户填写第1页上的表单.表单使用POST提交到第2页.第2页使数据库插入,但需要插入存储在会话变量中的用户ID,所以我需要做一个会话启动来获取该会话变量,但这阻止我在最后使用头重定向来停止重新意见书.我不想在第1页上将用户ID设置为隐藏输入,因为这很容易欺骗.我显然做了一些不符合最佳实践的事情,我该怎么办?
<?php
@session_start();
require_once '../Classes/Communication.php';
require_once '../Classes/Communication_db.php';
$noteDate=$_POST["noteDate"];
$noteContact = $_POST["noteContact"];
$note= $_POST["note"];
$custID = $_POST["custID"];
$comm = new Communication();
$comm->setCustomerID($custID);
$comm->setCommunicationDate(date("Y-m-d", strtotime($noteDate)));
$comm->setCustomerContactID($noteContact);
$comm->setNotes($note);
$comm->setUserID($_SESSION["userID"]);
Communication_db::saveCommunication($comm);
header("Location: ./index.php?action=newCustomer",303);
?>
Run Code Online (Sandbox Code Playgroud)
在<?php标记之前删除空格.那个空格被发送出来然后你就不能打电话了header().
此外,您可以在较早的位置调用session_start(或者库正在执行此操作).你只能打电话一次.试试这个:
if (!isset($_SESSION)) {
session_start();
}
Run Code Online (Sandbox Code Playgroud)