Php 用于更改会话变量的脚本

Php 用于更改会话变量的脚本,php,Php,我想要的是在执行脚本时更改会话变量 在我给出的示例中,SESSION变量没有改变。它始终处于关闭状态,可以更改为打开注册 'periodoinscripcion.php' <?php session_start(); $inscripcioncerrada = "inscripcion.php"; // CLOSE $inscripcionabierta = "registrar.php"; // OPEN $_SESSION['estadoInscripcion'] = $in

我想要的是在执行脚本时更改会话变量

在我给出的示例中,SESSION变量没有改变。它始终处于关闭状态,可以更改为打开注册

'periodoinscripcion.php'

<?php 

session_start();


$inscripcioncerrada = "inscripcion.php"; // CLOSE
$inscripcionabierta = "registrar.php"; // OPEN

$_SESSION['estadoInscripcion'] = $inscripcioncerrada;


if (isset($_REQUEST["estado"])) {
$_SESSION['estadoInscripcion'] = $_REQUEST['estado']; 
}

?>

和'periodosinscripion\u abrir\u registro.php'

<script language="javascript">

    var nuevoEstado = '$inscripcionabierta'; 
    xhr = new XMLHttpRequest(); 

    xhr.open('POST', 'periodoinscripcion.php'); 
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    xhr.send(encodeURI('estado=' + nuevoEstado));

</script>

var nuevoEstado=“$inscripcionabierta”;
xhr=newXMLHttpRequest();
open('POST','periodoinscripcion.php');
setRequestHeader('Content-Type','application/x-www-form-urlencoded');
send(encodeURI('estado='+nuevoEstado));

我不知道你为什么用这种方式构建php文件,但也许这样可以解决:

js

 var nuevoEstado = 'registrar'; 
 xhr = new XMLHttpRequest(); 

 xhr.open('POST', 'periodoinscripcion.php', true);
 var params = 'estado=' + nuevoEstado;
 xhr.open('POST', url, true);

 //Send the proper header information along with the request
 xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
 xhr.send(params);
php

<?php 

session_start();


$inscripcioncerrada = "inscripcion.php"; // CLOSE
$inscripcionabierta = "registrar.php"; // OPEN

$_SESSION['estadoInscripcion'] = $inscripcioncerrada;


if (isset($_POST["estado"])) {
   $_SESSION['estadoInscripcion'] = $_POST['estado']; 
}

尝试使用$\u POST而不是$\u请求。您还可以
var\u dump($\u POST);退出
要检查实际发送到页面的变量是什么,即使这样做有效,它也会在会话中存储字符串“$inscripcionabierta”,而不是“register.php”,可能是这个
$\u会话['estadoInscripcion']=$\u请求['estado']
应更改为此
$\u会话['EstadoInscription']=$inscripcionabiertadeceze否您能修改我的代码并显示为答案吗?