dongzaheng4449 2011-11-07 21:12
浏览 43
已采纳

“不推荐使用:session_is_register()”错误 - PHP

First of all, I just started PHP. I know my methods might not be the most efficient, but please try to remember that I'm new to all of this. Examples work great.

I'm trying to write a simple php code for that asks the user three questions. One true/false, one multiple choice and one short answer. Each question is displayed on its own page.

When I try to run this, I get the following error:

 Error: Deprecated: Function session_is_registered() is deprecated on line 10

This script still runs with this error. The problem though is at the end of the quiz, the variable $correct does not seem to change. I printed the variable to see if it was changing and nothing gets printed so obviously something is wrong -- possibly the deprecated function error is the culprit.

Any help would be appreciated.

<?php
ini_set('session.gc_maxlifetime',900);
//echo ini_get("session.gc_maxlifetime"); 
session_start();
if($_SESSION['loggedin'] !== 1) {
header('Location: login.php');
exit;
}

if (!session_is_registered("loggedin"))
{
 $_SESSION["number"] = 0;
 $_SESSION["correct"] = 0;
}

$total_number = 3;

print <<<TOP
<html>
<head>
<title> History Quiz </title>
</head>
<body>
<h3> History Quiz </h3>
TOP;

$number = $_SESSION["number"];
$correct = $_SESSION["correct"];


if ($number == 0){
print <<<FIRST
<p> You will be given $total_number questions in this quiz. <br /><br/>
  You will have 15 minutes to complete it. <br /><br/>
  You cannot go back to change previous answers.<br /><br/>
  Here is your first question: <br /><br />
</p>
<p>1. Abe Lincoln was born in Illinois.</p>
<p>
    <label><input type="radio" name="question1" value="true" /> True </label>
    <label><input type="radio" name="question1" value="false" /> False </label>
</p>
FIRST;

if (isset($_POST['submit'])) {

$selected_radio = $_POST['question1'];

if ($selected_radio == 'false') {
   $correct++;
   $_SESSION["correct"] = $correct;
   print $correct;
}
}
}


if ($number == 1){
print <<<SECOND
<p>2. In what state was the battle of Gettysburg fought?</p>
<p>
    <label><input type="checkbox" name="question2" value="Texas" /> a) Texas </label><br/>
    <label><input type="checkbox" name="question2" value="Pennsylvania" /> b) Pennsylvania   
 </label><br/>
    <label><input type="checkbox" name="question2" value="Virginia" /> c) Virginia </label><br/>
    <label><input type="checkbox" name="question2" value="West Virginia" /> d) West Virginia     
 </label>
</p>
SECOND;

if (isset($_POST['submit'])) {

$selected_checkbox = $_POST['question2'];

if ($selected_checkbox == 'Pennslyvania') {
   $correct++;
   $_SESSION["correct"] = $correct;
   print $correct;
}
}
}


if ($number == 2){
print <<<THIRD
<p>3. The last name of the commander of the Army of North Virginia was __________.</p>
<p>
    <input type='text' id='question3' />
THIRD;

if (isset($_POST['submit'])) {

$selected_answer = $_POST['question3'];

if ($selected_answer == "lee") {
   $correct++;
   $_SESSION["correct"] = $correct;
}
}
}


if ($number >= $total_number)
{
print <<<FINAL_SCORE
Your final score is $correct correct out of $total_number. <br /><br />
Thank you for playing. <br /><br />
FINAL_SCORE;
session_destroy();
}
else
{
$number++;
$_SESSION["number"] = $number;
$script = $_SERVER['PHP_SELF'];
print <<<FORM
<form method = "post" action = $script>
<input type = "submit" value = "Check Answer" />
</form>
FORM;
}

print <<<BOTTOM
</body>
</html>
BOTTOM;
?>
  • 写回答

1条回答 默认 最新

  • duanpo2037 2011-11-07 21:16
    关注

    function session_is_registered() is depcrecated, just use something like isset($_SESSION['blah']) to check

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?