doubi7739 2011-11-22 13:46
浏览 188

使用header()将数据从一个PHP页面传递到另一个PHP页面

I want to send data from one PHP file to another PHP file in a subfolder where the first PHP file is present. I have a folder named folder1 which has contains a PHP file named file1.php and I want to call another file named file2.php in a subfolder of folder1 named folder2. I am using the header() function like this in file1.php:

$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'folder1/folder2/file2.php';
header("location:http://$host$uri/$extra?sms=".$msg."&num=".$msg_num);

Data is not passing. Is there any solution using header()? I can't use cURL because of some restrictions.

  • 写回答

2条回答 默认 最新

  • douzhan1994 2011-11-22 13:56
    关注

    Without an example of the variables you want to send, it's kind of hard to tell what the problem might be, but a possible problem could be the characters in the variables.

    To make sure there are no invalid characters, you can use urlencode(), perhaps in combination with htmlentities(), see the manual:

    header("location:http://$host$uri/$extra?sms=".urlencode($msg)."&num=".urlencode($msg_num));
    
    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False