PHP сессии работают по-разному xampp и web - PullRequest
0 голосов
/ 01 июля 2018

Когда я пытаюсь открыть 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>

Сайт js.php
Xampp Js.php
Редактировать 1: я не могу сделать session_start (); в js.php как это выдаст ошибку index.php
(сессия уже началась.) Удаление заголовка не сработало.

1 Ответ

0 голосов
/ 01 июля 2018
<?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

сделать это изменение не нужно использовать заголовок ('Содержание: текст / javascript');

...