我想在不使用表单的情况下将'id'传递到index.php,但它不起作用
我想将我想在不使用表单的情况下将'id'传递到index.php,但它不起作用,php,html,Php,Html,我想将id传递到index.php中,我的代码如下所示 我的main.php是: <?php $rd = dirname(__FILE__); //To Get the Directory Path... $request[]=''; // To make an empty array if (empty($request[1]) && empty($request[2]) && isset($_SESSION['l_user'])) {
id
传递到index.php中,我的代码如下所示
我的main.php是:
<?php
$rd = dirname(__FILE__); //To Get the Directory Path...
$request[]=''; // To make an empty array
if (empty($request[1]) && empty($request[2]) && isset($_SESSION['l_user']))
{
$request[1] = 'index';
$request[2] = '?id=1';
include_once($rd.'/php_includes/'.$request[1].'.php'.$request[2]); //i think the problem might be here...
}else {
$request[1] = 'index';
$request[2] = '?id=2';
include_once($rd.'/ph p_includes/'.$request[1].'.php'.$request[2]); // and might be here
}
?>
但即使没有任何错误,它也不会有任何结果。它不工作。试试这个,您只需初始化一次
include_的值top,就可以在包含的文件(即index.php)中获得初始化的变量。请注意,您不能在includead require中以查询字符串的形式传递该值
$id = '1';
include_once($rd.'/php_includes/'.$request[1].'.php');
在index.php中
if($id=="1"){
}else{
}
您应该使用header
而不是require\u once
,因为require\u once
类似于include
它将包含的代码复制到文件中
<?php
$rd = "http://ip_address"; // ip_address or dns name
$request[]=''; // To make an empty array
if (empty($request[1]) && empty($request[2]) && isset($_SESSION['l_user']))
{
$request[1] = 'index';
$request[2] = '?id=1';
header('Location:'.$rd.'/php_includes/'.$request[1].'.php'.$request[2]); //i think the problem might be here...
}else {
$request[1] = 'index';
$request[2] = '?id=2';
header('Location:'.$rd.'/php_includes/'.$request[1].'.php'.$request[2]); // and might be here
}
?>
这是示例代码还是实际代码?因为使用数组传递相同的URL而不是传递整个字符串是不常见的
include_once($rd.'/php_includes/index.php?id=1');
您的代码可能会变成这样
<?php
$rd = dirname(__FILE__); //To Get the Directory Path...
# it seems that the session is important :)
if (isset($_SESSION['l_user']))
{
$id=1;
}else {
$id=2;
}
include_once($rd.'/ph p_includes/index.php?id='.$id);
?>
启用错误报告:ini\u集('display\u errors',1);错误报告(E_全部)代码>。然后您将看到错误。您不能像这样将参数传递给include,请将$id
设置为变量,然后它将在include中可访问。请尝试使用Thank you FDL。该帮助我不知道我无法在include和requre中将值作为查询字符串传递。这非常有用,多亏了alot.dude,我无法在include#u中将值作为查询字符串传递一次,因此它无法正常工作,然后删除此?id='.$id
代码段和内部index.php检查如果$id==1{会话设置}否则{会话未设置}
<?php
$rd = dirname(__FILE__); //To Get the Directory Path...
# it seems that the session is important :)
if (isset($_SESSION['l_user']))
{
$id=1;
}else {
$id=2;
}
include_once($rd.'/ph p_includes/index.php?id='.$id);
?>