如何将会话变量值插入字符串数组


How to insert session variable value into string array

我想执行以下操作:

     $_SESSION['SESS_VERSION'] = $member['Version'];
     session_write_close();
     header("location: '$_SESSION['SESS_VERSION']'");
     exit();

现在我得到:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

如何在字符串中获取此值?

正确连接字符串:

header('location: '.$_SESSION['SESS_VERSION']);

header("location: {$_SESSION['SESS_VERSION']}");

文档

  • PHP 字符串连接 - http://php.net/manual/en/language.operators.string.php
  • PHP 字符串 - http://php.net/manual/en/language.types.string.php

删除会话周围的引号,例如,

$sess = $_SESSION['SESS_VERSION'];
header("location: $sess");

或者你可以这样做,

header("location:". $_SESSION['SESS_VERSION']);