如何仅使用 get 方法参数在我的 php 中设置我的 URL 模式
How to Set my URL pattern in my php using get method parameters only
我的目录(/帐户)中有 3 个 php 个文件:
- index.php
- login.php
- signup.php
正在访问本地主机中的文件夹:
http:localhost/account ==> 打开默认(index.php 文件)
我想访问 login.php 和 signup.php 使用:
=> http:localhost/account?login
和
=> http:localhost/account?signup
分别
这是我在 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
}
请帮我找到一个方法来获取我的 URL...
您有 login 和 signup 密钥,但没有值,因此您应该使用 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;
}
我的目录(/帐户)中有 3 个 php 个文件:
- index.php
- login.php
- signup.php
正在访问本地主机中的文件夹:
http:localhost/account ==> 打开默认(index.php 文件)
我想访问 login.php 和 signup.php 使用:
=> http:localhost/account?login
和
=> http:localhost/account?signup
分别
这是我在 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
}
请帮我找到一个方法来获取我的 URL...
您有 login 和 signup 密钥,但没有值,因此您应该使用 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;
}