1

session_start()即使在这两个文件上,我也无法访问我的会话变量。

文件1.php

<?php
  session_start();

  ...

  if($responseCode == 1) {
    $_SESSION['card_id']    = $_POST['card_id'];
    $_SESSION['password']   = $_POST['password'];
    print '<script type="text/javascript">'; 
    print 'window.location = "http://domain.com/File2.php";';
    print '</script>';
  }
?>

文件2.php

<?php
  session_start();

  $account = getAccount();

  echo "document.write('$account')";

  function getAccount() {
    $card_id = $_SESSION['card_id'];
    $string = "card = " . $card_id ;
    return $string;
  }
?>

File1.php 执行 curl 请求,如果成功,它会重定向到 File2.php。但是,我只看到card :没有输入的 card_id。

4

1 回答 1

1

它不起作用,因为 www 被视为子域,因此会话不会持续。您可以通过 2 种方式解决此问题 -

  1. 我认为这是更好的方法,使用 htaccess 将所有非 www url 重定向到 www url,这对 SEO 更好

  2. 查看 PHP 手册,了解如何跨多个子域设置会话。

如果您好奇,这篇文章解释了 www 是如何被视为子域的。

于 2013-08-15T15:50:10.967 回答