我有一个index.php页面,我正在使用switch语句来包含基于uri的脚本(php request uri)并获取url参数来执行某些操作(激活帐户或更改密码),然后method返回在主html页面中打印的消息。
问题是一旦脚本执行,带有get参数的输入url(来自url栏)仍然存在。当用户按下登录按钮时,它将再次执行。
我需要清除(或更准确地重定向,如标题)栏中的网址并打印从方法返回的消息。
如果我使用标题,则$ msg将丢失,并且不会打印任何消息。如果我再使用另一个,那就是同样的故事。
// array whitelisting the permitted urls
// just 4: login, send_mail, recover_pwd and register (each pointing to his php file)
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// some more security checks
if ($url != '/send_mail' && $url != '/recover_pwd' && $url != '/register' && $url != '/activateAccount')
$url = '/login'; // this must be always the default page if none of the above are requested.
switch ($url) {
case '/recover_pwd': // here users request a password change
if (isset($_GET['code']) && isset($_GET['email'])) {
include('pages/rp_get.php'); // this is the get script(not included insde the array/html):
//validates the code, changes the password and sends a mail with the new one then we have to redirect the user to the login page and print the message
header('Location: /'); // this will clear the address bar and the $msg var
}
}
break;
case '/activateAccount': // this is just the script that validates the code and activates the account
include('pages/activate_acc.php'); // (not included insde the array/html) then we have to redirect the user to the login page and print the message
header('Location: /');
}
break;
case '/login': // this is the login page
include('pages/header_pages/login_post.php'); // the login post script must be before any DOM output so it can perfom a redirection using header()
break;
default: // i'm not sure if there should be a default case...
$url = $url;
break;
}
// include the main html
include('themes/aet/main.php');
这是main.php:
// HTML BASIC STRUCTURE
// BODY -> Header
// MAIN tags
<?php
$include = '/404';
if (array_key_exists($url, $includes)) {
$include = $url; // this includes the pages from the array
}
include($includes[$include]);
?>
// here I print the msg (@ is just a temp hack)
if(@$msg != NULL) {
// check what type of message is and print it
}
我需要找到一种方法来做到干净优化。我不想要一个沉重的索引页面。
我怎样才能做到这一点?