【发布时间】:2017-04-13 06:44:21
【问题描述】:
我通过单击按钮发送了用户 ID
<form action="https://www.mysite.co.uk/some/index.php" method="POST">
<input type="hidden" name="userid" value="ZUpmenVaN0ZVTTBmejNGZGNwZGFha1NmR0tuSjdaT3VYdjV5cTF4WGtISzRvK0ptOC9vZmQyc3J3T3cwTmplbWZ3alhod0xMYUhlQ2xLSng4WWI4ZEE9PQ2">
<input type="submit" value="Go" style="font-size:14px; padding:20px;">
</form>
然后我获取用户 ID 并在普通 php 页面中使用它(outsidecodeigniter)
www.mysite.co.uk/some/index.php
<?php
session_start();
<?php
if (isset($_POST['userid'])) {
$_SESSION['userid'] = $_POST['userid'];
$userid = $_SESSION['userid'];
}
if (isset($_SESSION['userid'])) {
echo "You are logged in and have access to these tests.";?>
code here
<?php
} else {
header ('location: ../index.htm');
}
?>
我现在需要在控制器中使用用户 ID,该控制器将数据发送到代码点火器中的数据库
ci 控制器
private function getResults()
{
$this->load->library('session');
$this->session->set_userdata('user_id', $_POST['userid']);
$userID = $this->session->userdata('user_id');
$score = $this->actions->getSentEmailCount();
$percentilescore = $percentile = $this->actions->getPercentile($score);
$testID = '134';
{
$data['emailcount'] = $score = $this->actions->getEmailCount();
$data['sentEmailCount'] = $score = $this->actions->getSentEmailCount();
$data['score'] = $score = $this->actions->getScore();
$data['percentile'] = $percentile = $this->actions->getPercentile($score);
$data['timespent'] = $this->input->get('time');
};
$adddata = array(
'uniID' => '5',
'testName' => 'Abintegro E-Tray test',
'testID' => $testID,
'total' => '20',
'useInPercentile' => '1',
'correct' => $score = $this->actions->getScore(),
'percent' => $score = $this->actions->getScore(),
'percentile' => $percentilescore,
'dateTaken' => date('Y-m-d H:i:s'),
'timeSpent' => $this->input->get('time'),
'userID' => $userID
);
$this->actions->add_record($adddata);
return $this->load->view('client/results', $data);
}
我收到一个错误
消息:未定义的索引:用户 ID
有人能看出我为什么会变成 null 吗?
【问题讨论】:
-
错误信息是什么?试试
var_dump($_SESSION)有吗?或者您的 this.php 无法正常工作。 -
get null,我在某处丢失了值
-
可能,您正在重置会话的全局变量。
-
嗯好的,谢谢。生病查看会话可能重新启动的代码
-
在 CI 目录之外工作也没关系,
$_SESSION是一个全局变量,可以在任何地方访问。
标签: php codeigniter session