Hi!
I'm trying to understand what it is that I'm looking at when I see a URL as mywebsite.com/login.php and when I see mywebsite.com/?x=login. (For simplicity, I'm going to use a file called 'login'.) I like the second format better than the first, but I'm having a very hard time figuring out what it is that I'm seeing.
When I see mywebsite.com/login.php, I recognize that as a file that's called login.php.
When I see mywebsite.com/?x=login, I think I see a CMS in action or something to do with MySQL. Am I correct about this?
I'm sure I once saw a tuturial for building a php webpage where all the sections were in the same file and clicking on a link would reveal another part of the file, previously hidden. The URLs were similar to mywebsite.com/?x=login, but the format I'm after is here x points to a single file on the server, not a hidden section in a file.
Also, does the second URL structure have to be "?x=filename"? Can it be something like "?d=filename"?
Any help would be appreciated. I've been having no luck in figuring out the two URLs on my own.
Thank you.
mysite.com/login.php versus mysite.com/?x=login question
Moderator: General Moderators
First off, the x in x=login simply signifies a GET method variable, as in the variable $_GET['x'] (or simply $x) in the script will be set to 'login'. There are several ways this might be used by the script, usually based on some logic that determines what should happen if $x is set to various keywords, e.g.
So you can see that if x=login that a function might be called to log the user in. Same for logout. If other options are passed, other methods might be used, or different pages included. You can also look at it as being part of a controller pattern, so that the page object calls a method named 'login', that performs a login type task.
Yes, the variable might be named 'd' or 'action' or whatever makes sense to you. There might be a second or third variable involved that sets other attributes on the page, e.g. mywebsite.com/?x=login&p=2
PHP Manual: Variables
PHP Manual: Predefined Variables
PHP Manual: Predefined Variables: $_GET
Code: Select all
// set array for the only methods allowed for x
$allowed= array('login', 'logout', 'register', 'reset_pass');
// ternary operator logic assigns $x to the appropriate value
$x= ( in_array($_GET['x'], $allowed) ) ? $_GET['x'] : 'index';
// further logic determines action taken based on $x value
switch ( $x ) {
case 'login':
do_login();
break;
case 'logout':
do_logout();
break;
case 'register':
include('register.php');
break;
case 'reset_pass':
include('reset.php');
break:
case 'index':
default:
display_index();
}So you can see that if x=login that a function might be called to log the user in. Same for logout. If other options are passed, other methods might be used, or different pages included. You can also look at it as being part of a controller pattern, so that the page object calls a method named 'login', that performs a login type task.
Yes, the variable might be named 'd' or 'action' or whatever makes sense to you. There might be a second or third variable involved that sets other attributes on the page, e.g. mywebsite.com/?x=login&p=2
PHP Manual: Variables
PHP Manual: Predefined Variables
PHP Manual: Predefined Variables: $_GET