我有一个html页面
<html>
<head>
</head>
<body>
<form>
<div><a href="MySubmissionView.php">Number of Applications:</a></div>
<div><a href="MySubmissionView.php">Submitted Applications:</a></div>
</form>
</body>
</html>
我有一个php页面"MySubmissionView.php",用于一些进程。在我的php页面中,我如何知道我点击了哪个链接。?提前感谢
向hrefs添加查询字符串。例如MySubmissionView.php?page=number和MySubmissionView.php?page=已提交。您可以使用$_GET('paramname')
从php访问查询字符串。这里有一个例子:
HTML:
<html>
<head>
</head>
<body>
<form>
<div><a href="MySubmissionView.php?page=number">Number of Applications:</a></div>
<div><a href="MySubmissionView.php?page=submitted">Submitted Applications:</a></div>
</form>
</body>
</html>
PHP:
if (isset($_GET['page']))
if($_GET['page'] == 'number') {
// process page number here
} elseif($_GET['page'] == 'submitted') {
// process page submitted here
}
}
<div><a href="MySubmissionView.php?id=xx1">Number of Applications:</a></div>
<div><a href="MySubmissionView.php?id=xx2">Submitted Applications:</a></div>
Php页面:
if (!empty($_GET['id'])) {
echo '<p>The id is: '.$_GET['id'].'</p>';
// do something else
}
<html>
<head>
</head>
<body>
<form>
<div><a href="MySubmissionView.php?click=1">Number of Applications:</a></div>
<div><a href="MySubmissionView.php?click=2">Submitted Applications:</a></div>
</form>
</body>
</html>
MySubmissionView.php:
if($_GET['click'] == 1){
echo "first a clicedk";
}else{
echo "second a clicedk";
}
<html>
<head>
</head>
<body>
<form>
<div><a href="MySubmissionView.php?go=1">Number of Applications:</a></div>
<div><a href="MySubmissionView.php?go=2">Submitted Applications:</a></div>
</form>
</body>
上面是您的HTML,MySubmissionView.PHP的PHP应该如下所示。
<?php
$go = "";
if(isset($_GET)){
if(isset($_GET['go'])){
$go = $_GET['go'];
}else{
// do something if '$_GET['go']' is not set
}
}else{
// Do something if u don't get a $_GET Request
}
echo 'Clicked Page'.$go;
?>
--
if(isset($_GET))
将检查页面是否获得GET/Post请求。阅读Get/Post Methods