私の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 />