I have 3 php files in my directory(/account):
- index.php
- login.php
- signup.php
Accessing the folder in my localhost:
http:localhost/account ==> opens the default(index.php file)
I want to access the login.php and signup.php using:
JavaScript
x
=> http:localhost/account?login
and
JavaScript
=> http:localhost/account?signup
respectively.
Here is my code in the index.php
JavaScript
<?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
}
Please help to get me a way to get my URLs like that…
Advertisement
Answer
You have the key login and signup but no value so you should check whether the key exists with isset()
.
JavaScript
<?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
}
In case you want to use switch
instead,
JavaScript
switch(true) {
case isset($_GET['login']):
break;
case isset($_GET['signup']):
break;
}