问题描述
我的目录 (/account) 中有 3 个 PHP 文件:
访问我本地主机中的文件夹:
http:localhost/account ==> 打开默认(index.PHP 文件)
我想访问 login.PHP 和 signup.PHP 使用:
=> http:localhost/account?login
和
=> http:localhost/account?signup
分别。
<?PHP
if($_GET['login']){
include('login.PHP')
} else {
// Load homepage of the site
// which in my case http://localhost
}
if($_GET['signup']){
include('signup.PHP')
} else {
// Load homepage of the site
// which in my case http://localhost
}
解决方法
您拥有登录和注册密钥但没有值,因此您应该使用 isset()
检查密钥是否存在。
<?php
if(isset($_GET['login'])){
include('login.php')
} else {
// Load homepage of the site
// which in my case http://localhost
}
if(isset($_GET['signup'])){
include('signup.php')
} else {
// Load homepage of the site
// which in my case http://localhost
}
如果您想改用 switch
,
switch(true) {
case isset($_GET['login']):
... break;
case isset($_GET['signup']):
... break;
}