我的问题是如何切片PHP代码并执行?我用循环制作了一个子网址,我想将子网址添加到主网址。
例如
子网址是:&a=1&b=2&c=3
主网址是:http://#site#.com/
实际上我想用这种方式重定向到带有 header() 代码的某个页面!
像这样的代码...
<?php
/////////////////slice 01/////////////////
header("location:
/////////////////slice 01/////////////////
/////////////////slice 02/////////////////
echo $_SERVER['HTTP_REFERER'];
for($i=0;$i<5;$i++)
{
if(!empty($link[$i]))
{
echo "&";
find_link($link[$i]);
}
}
/////////////////slice 02/////////////////
/////////////////slice 03/////////////////
");
/////////////////slice 03/////////////////
我不能完全理解你想实现什么,但你可以使用爆炸函数
$subarray = explode("&",$sub_url);
这将为您提供子 URL 中的值数组。和重定向后
header("location:".$_SERVER['HTTP_REFERER']."?".implode("&",$subarray));
我想你想做的是获取网址
的一部分www.site.com/page1/&a=1&b=2&c=3
然后将其与标头位置组合并重定向到该位置。
www.site.com/page2/&a=1&b=2&c=3
首先,您需要在 url
中声明值http://#site#.com/page1?a=1&b=2&c=3
然后在 php 中,如果您使用的是面向对象的方法,请使用以下代码
<?php
//get values from first url
if (isset($GET['a'], $GET['b'], $GET['c'])){
//store the values in variables
$a = $GET['a'];
$b = $GET['b'];
$c = $GET['c'];
//pass the variables to the function
$yourclassvariable->yourfunctionname($a,$b,$c);
// after function is successful pass values to new url
header("location:www.site.com/page2?a=$a&b=$b&c=$c");
}
?>
这应该可以解决您的问题