在我的login.php頁我有這樣的:PHP頭位置與數組鍵和allowed_operations
$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功能富被調用。
是否有可能我可以在不添加href的情況下調用這個url http://example.com?p=foo在我的html標記中?
例如一些喜歡這樣的:
<?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 />
''不應該是''? – mishu 2012-03-12 14:04:17
我知道這就是爲什麼我來這裏問這個問題。我如何在不添加的情況下做到這一點。 – jQuerybeast 2012-03-12 14:06:23
@mishu不,不要緊。 href會自動附加參數到當前的uri,所以定義這兩種方式都是正確的。 – 2012-03-12 14:09:39