【问题标题】:How can I redirect to a PHP page with an <a> tag? Also how can I pass an ID number through the URL with it?如何重定向到带有 <a> 标签的 PHP 页面?另外,如何通过 URL 传递 ID 号?
【发布时间】:2018-03-04 11:18:35
【问题描述】:

对于我的 PHP 项目,我正在使用表单的 post 方法,并且我希望能够重定向到带有 &lt;a&gt; 标记的 PHP 页面。

这是我想用来重定向的代码,但我不知道如何使它与&lt;a&gt; 标记一起使用。

$query_string = ['item' => $_SESSION['items']];
$url_query = http_build_query($query_string);
header("location:detailPage.php?$url_query");

另外,如何通过 URL 从当前页面将 ID 号传递到不同的 PHP 页面?

【问题讨论】:

  • 简单关闭php标签然后&lt;a href="detailPage.php?&lt;?php echo $url_query; ?&gt;"&gt;Any Text&lt;/a&gt;
  • 为什么要使用&lt;a&gt;标签

标签: php http-redirect


【解决方案1】:

您可以使用嵌入php 代码的html 标记

<a href="detailPage.php?id=<?php echo $url_query; ?>">TEXT</a>

detailPage.php 你会这样称呼它

if(isset($_GET['id'])//getting id from url using $_GET request
{
   $id = $_GET['id'];//storing in php variable
}

我希望这会对你有所帮助。如果有什么问题请告诉我

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 2021-12-26
    • 2021-07-25
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多