我认为您正在寻找的是使用隐藏输入来保持您的变量在页面之间传递。
在表单中使用这样的东西:
<form method='get'>
<input type='hidden' name='client' value='1'>
// Your other inputs
</form>
这样,当您获得一个输入时,您可以使用一些简单的 PHP 代码将其从一个页面传递到另一个页面,从 URL 中获取它并根据需要再次显示它。
编辑:(进一步解释)
当您通过 URL 将数据从一个页面传递到另一个页面时,您可以使用一些简单的 PHP 代码来查看是否存在将其进一步传递的内容 - 如下所示:
<?php //page1.php
if(isset($_GET['user']))
{
$user=htmlspecialchars($_GET['user']);
}
if(isset($_GET['photo']))
{
$photo=htmlspecialchars($_GET['photo']);
}
// Check for anything else you want as needed.
?>
然后,在实际制作链接时,您可以执行以下操作:
<?php
$baseAddress="<a href='thePageIwant.php?thisVar=3";
if(isset($user))
{
$baseAddress.="&user=".$user;
}
if(isset($photo))
{
$baseAddress.="&photo=".$photo;
}
// Add any other variables as needed
$baseAddress.="'>
?>
在页面的 HTML 输出部分,您可以使用以下代码:
<p>Some text and then a link <?php echo $baseAddress;?>Your Link Text</a></p>
您的链接将与通过 URL 传递的所有其他变量一起出现。在这种情况下,如果用户被传递到 ID 为 4 的页面,而照片被传递到 ID 为 6 的页面,则 HTML 输出将是:
<p>Some text and then a link <a href='thePageIwant.php?thisVar=3&user=4&photo=6'>Your Link Text</a></p>
如果仅在 URL 中传递了用户,并且没有 photo=6,则输出将是这样的:
<p>Some text and then a link <a href='thePageIwant.php?thisVar=3&user=4'>Your Link Text</a></p>