doulai6469 2012-01-09 21:46
浏览 219
已采纳

使用$ _SESSION将变量从PHP传递到另一个PHP

I'm having a problem passing a variable from one PHP file to another PHP file. I'm trying to send the varialbe $insert to another PHP file that will just display it. For the life of me, I can't figure out why it won't work.

Any help would be great! Thanks.

1st PHP File (Sending $insert to $_SESSION['finalimage'])

<?php

 session_start();
 $insert = rand(5, 1500);
 $_SESSION['finalimage'] = $insert;

 header("Location: http://www.shmoggo.com/snapshot/snapshot_view.php");

 echo base64_decode($_POST["image"]);

 $final = base64_decode($_POST["image"]);


 $newpath = "uploads/" . $insert . ".jpg"; 
 file_put_contents($newpath, $final);

 ?>

2nd PHP File (Receiving $insert from $_SESSION['finalimage'])

 <?php

 session_start();
 $insert = $_SESSION['finalimage'];
 echo "Image Number = ". $insert;

 ?>
  • 写回答

1条回答 默认 最新

  • donglaogu3788 2012-01-09 22:15
    关注

    First thing to check is how your PHP installation is supporting sessions. There are two possible methods for "persisting" the session ID between requests:

    1) using cookies or 2) using "URL rewriting" (ie each URL passes a sessionid value)

    If you are using cookies check to see if your server is in fact sending a cookie to your browser.

    If you are using url-rewriting the Location header that you are sending that re-routes the client browser to "snapshot_view.php" will need to be modified to include the session id. Like this:

    $reroute = 'Location: http://www.shmoggo.com/snapshot/snapshot_view.php?PHPSESSID=' . session_id();
    header($reroute);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信