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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效