第一页有两个超链接:
<p> COE <a href="page2.php">here</a></p>
<p> SWE <a href="page2.php">here</a></p>
我想要的是:当用户单击第一个链接时,page2 应该显示此链接:
<p> academic transcript <a href="A.php">here</a></p>
当用户单击第二个链接时,page2 将显示一个不同的链接,即:
<p> courses list <a href="B.php">here</a></p>
我能做到吗??
您需要以某种方式分隔这两个链接。您可以传递 $_GET
参数,并在第二页上检查它是否已设置。
如果您编辑指向以下内容的超链接
<p>COE <a href="page2.php?page=A">here</a></p>
<p>SWE <a href="page2.php?page=B">here</a></p>
然后,我们可以在 PHP 中使用 $_GET
在您的 URL 中查找参数page
的值,如下所示。评论应该或多或少地解释正在发生的事情。
if (!empty($_GET['page'])) {
// If that parameter is set, we can check what it's set to
switch($_GET['page']) {
case "A":
// If the value was A, we display this
echo '<p>academic transcript <a href="A.php">here</a></p>';
break;
case "B":
// If the value was B, we display this
echo '<p>courses list <a href="B.php">here</a></p>';
break;
default:
// It didn't match any of the values, you can display a default page
echo "Not a valid page";
}
} else {
// You can put whatever you want here,
// but if no values of ?page= is set, whatever is inside here will be displayed
echo "Nothing to show!";
}
在您的主页中添加以下内容:
<p> COE <a href="page2.php?pageA">here</a></p>
<p> SWE <a href="page2.php?pageB">here</a></p>
在第 2 页.php添加以下内容:
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (strpos($url,'pageA') !== false) {
echo '<p> academic transcript <a href="A.php">here</a></p>';
} elseif (strpos($url,'pageB') !== false) {
echo '<p> courses list <a href="B.php">here</a></p>';
}
上面发生的事情是 PHP 正在检查是否pageA
或pageB
作为参数传递,分别修改页面以处理任一事件。