0

我在 XP 上安装了 Opera 12.15,并在 XAMPP 和 localhost 上启用了 cookie。没有.htaccess。

1)我不明白为什么以下会话变量在 Opera 中不存在,而在其他主流浏览器中却存在。仅在 Opera 中,如果您在表单被接受后重新访问页面(通过链接),会话变量已经消失并且表单再次显示。如果我只是刷新页面没关系(即变量仍然存在)。

2)我还有一个次要问题,如下所示,我打开了一个 php 标签并启动了一个“if”语句,然后关闭了 php 标签,输入了一些 html,打开了一个新的 php 标签,关闭了“if”和终于关闭了第二个 php 标签。这是有效的代码吗,我最初被教导在“if”中回显 html,并且只有一组 php 标签?前者更容易且有效,我看到它在其他地方使用过。

提前致谢。

<?php
// Turn on error reporting
ini_set('display_errors', 1);
error_reporting(E_ALL);

session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Opera Session Variable</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<?php
// create a test variable to confirm other session variables outside of Form are   persisting
$_SESSION['test'] = 'Test';

// function to print session variables
function print_array( $_SESSION )
{
echo '<pre>$_SESSION<br />' . "\n";
print_r($_SESSION);
echo "</pre>\n";
}   

// process the submitted form
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
if (isset($_POST['formaccept'])) {
$_SESSION['formaccepted'] = $_POST['formaccept'];
}
}

// print the session variables
print_array( $_SESSION );

// only display the form if it has not previously been accepted in this session
if (!isset($_SESSION['formaccepted'])) {
?>
<p><b>This parargraph should only display if the form has not been accepted in the current session.</b></p>
<br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="formaccept" value="Accept" />
</form>
<?php
}
?>

</body>

</html>
4

1 回答 1

0

一定是歌剧处理缓存的方式,我看不出你的代码有任何错误。

至于您的第二个问题,该语法有效,但通常不推荐使用,因为它使布局变脏,充满了片段。

于 2013-04-29T11:00:14.947 回答