gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:08:16 25 4
gpt4 key购买 nike

我想将数据从一个 PHP 文件发送到第一个 PHP 文件所在子文件夹中的另一个 PHP 文件。我有一个名为 folder1 的文件夹,其中包含一个名为 file1.php 的 PHP 文件,我想调用另一个名为 file2.php 的文件folder1 的子文件夹名为 folder2。我在 file1.php 中使用这样的 header() 函数:

$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);

数据未通过。有没有使用 header() 的解决方案?由于某些限制,我无法使用 cURL

最佳答案

以下代码有效:

file1.php:

<?php

header( 'Location: inner/file2.php?x=1&y=2&z=3' );

?>

inner/file2.php:

<?php

print '<pre>';

var_dump( $_GET );

print '</pre>';

?>

访问 http://localhost/testing/file1.php 的结果是重定向到 http://localhost/testing/inner/file2.php?x=1&y= 2&z=3 显示:

array(3) {
["x"]=>
string(1) "1"
["y"]=>
string(1) "2"
["z"]=>
string(1) "3"
}

我建议复制这些测试文件并向自己证明使用传递值进行重定向的基本概念是有效的。然后,围绕已知良好的内核构建其余代码。祝你好运!

关于php - 使用 header() 将数据从一个 PHP 页面传递到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8227844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com