如何仅使用get方法参数在php中设置URL模式
我的目录(/account)中有3个php文件:如何仅使用get方法参数在php中设置URL模式,php,url,get,Php,Url,Get,我的目录(/account)中有3个php文件: index.php login.php signup.php 访问my localhost中的文件夹: http:localhost/account==>打开默认值(index.php文件) 我想通过以下方式访问login.php和signup.php: => http:localhost/account?login 及 分别 这是我在index.php中的代码 <?php if($_GET['login']){
=> http:localhost/account?login
及
分别
这是我在index.php中的代码
<?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文件的情况下,你能用switch来完成这个任务吗?是的,你能,有点棘手,但可能。它成功了!daniel@codeloaded.com
<?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
}
<?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(true) {
case isset($_GET['login']):
... break;
case isset($_GET['signup']):
... break;
}