【发布时间】:2012-03-12 13:58:39
【问题描述】:
在我的 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 />
【问题讨论】:
-
<a href="?login&p=foo">不应该是<a href="login.php?p=foo">吗? -
我知道这就是我来这里问这个问题的原因。如何在不添加 . 的情况下执行此操作
-
@mishu 不,没关系。 href 会自动将参数附加到当前 uri 中,因此定义两种方式都是正确的。
-
@IbrahimAzharArmar - 如果您已经在 login.php 上,这是真的.. 如果您来自任何其他页面,它只会添加一个名为 login 的空 var.. 但这不是重点问题..我认为..
-
@jQuerybeast 你想使用 $_GET 而不将它添加到 url?另外:
in_array(isset($_GET['p']), $allowed_operations)这看起来很破旧
标签: php header case operations