PHP会话以不同的方式工作xampp和web

时间:2018-07-01 11:13:24

标签: php xampp webserver

当我尝试打开js.php时,它在xampp中给出了错误,而在000webhost中则没有。我不明白为什么。
所以这是代码。 js.php

<?php
header('Content: text/javascript');
if($_SESSION['myjskey'] != hash('md5','examplekey')){
    die('No Auth');
}
$_SESSION['JSSESSID'] = 'change';//so that no one can access directly
?>
//secret js
alert('javascript done.');
//and some more js

index.php

<?php
session_start();
$_SESSION['myjskey'] = hash('md5','examplekey');
?>
<!DOCTYPE html>
<html>
<head>
    <title>PHP</title>
</head>
<body>
this is a test.
<script type="text/javascript"><?php include('js.php'); ?></script>
</body>
</html>

Website js.php
Xampp Js.php
编辑1:我不能执行session_start();在js.php中,因为它会给出错误index.php
(会话已开始。)删除标题无效。

1 个答案:

答案 0 :(得分:0)

<?php
//js
if($_SESSION['myjskey'] != hash('md5','examplekey')){
   die('No Auth');
}
$_SESSION['JSSESSID'] = 'change';//so that no one can access directly
?>
//secret js
  alert('javascript done.');
//and some more js

进行此更改无需使用 header('Content:text / javascript');