在我的login.php页面中,我有这个:
$allowed_operations = array('foo', 'lorem');
if(isset($_GET['p'])
&& in_array(isset($_GET['p']), $allowed_operations)){
switch($_GET['p']){
case 'foo':
// Code for 'foo' goes here
break;
case 'lorem':
// Code for 'lorem' goes here
break;
}
}
如果我在哪里调用 url http://example.com/login.php?p=foo函数foo被调用。
是否可以在我的 html 标记中不添加 href http://example.com?p=foo的情况下调用此 url?
例如像这样的东西:
<?php
if (array_key_exists("login", $_GET)) {
$p = $_GET['p'];
if ($p == 'foo') {
header("Location: login.php?p=foo"); // This doesn't work
// And if I remove the ?p=foo,
// it redirect to the page but
// the 'foo' function is not called
}
}
?>
和我的html:
<a href="?login&p=foo">Login Foo</a> <br />