php - 使用获取变量扩展链接

标签 php html css

我有这个链接:

www.something.com/index.php?page=teams

然后我有这个链接:

<a href="?profile=5">Profile</a>

我要实现的是这个链接:

www.something.com/index.php?page=teams&profile=5

但我得到的是这个:

www.something.com?profile=5

棘手的部分是我不能像这样写整个“路径”:

<a href="http://www.something.com/index.php?page=teams&profile=5">Profile</a>

因为它并不总是在“团队”页面上。

这可能是一个非常愚蠢的问题,但我真的想不通。

最佳答案

您必须在 href 中包含 page=teams 参数。

代替

<a href="?profile=5">Profile</a>

有点像

<a href="./page=teams&profile=5">Profile</a>

如果该链接是静态的,您必须更新 html 文件。 但是如果 page=anyvalue 那么你必须在你的 php 代码中动态生成 href 链接 例如:

<a href="<?php echo "./page=$page&profile=5"; ?>"></a>

其中 $page 是当前页面,例如 $page="teams"

关于php - 使用获取变量扩展链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21895814/

相关文章:

html - 页脚应该在页面/内容的底部

html - @media screen and (max-width :800px) not working, 在整个互联网上看了

php - PDO 多选查询

php - Eloquent 模型中 id 周围的引号在生产站点上是必需的,但在本地主机上不起作用

javascript - 创建多输入到单输出文本区域

html - 平滑滚动基础 5 不起作用

javascript - 响应式网格(高度问题)

c# - 在 php 中传输用户密码的安全方法

php - 将mysql信息动态放置在带有id的div中

javascript - 将 html 字符串渲染到 Canvas 而不显示 html 本身