G'day everyone,
I have a curiosity question. I'm totally new to server-side scripting and I'm curious, the few PHP pages I've created have all had 'standard' names like website.com.au/pagename.php
Lately I've seen more and more pages all with names like website.com.au/?xyz=something&more=html
Can someone explain to me the difference with the two naming conventions. Is the ?= type name just server generated name. Is the '?=' a better way to go is it more convenient or better way of scripting?
I don't know if this is the right forum to ask this, but can someone give me an example of a script that uses the '?=' naming and how it's done.
Thanks.
Page naming
Moderator: General Moderators
Re: Page naming
Hi NightShift,
PHP does not, by nature, run as an "Application". This means that unless you use an external reference, the changes you make on one page are lost when you move to another one. There are several ways of sending data between pages, though. Two very common ones are using forms, which can, in turn, generate either GET or POST data. POST data is when the information is sent to the page you specify in a way that is not viewable to the user. GET is what produces the ?variable=value format. One nice thing about GET data, is that you don't need a form to generate it, you can write it yourself if you want.
For example, let's say we want a page that follows a template, and has three links. Each link, when clicked, should reload the page, showing a specific passage of text. To achieve this, we'll use GET data to pass a value to the script, and then we'll let PHP parse the GET data and return a result.
Our HTML for the links will look like this:
Now, the PHP:
Does that help you out a bit? If you'd like some more clarification, let me know.
PHP does not, by nature, run as an "Application". This means that unless you use an external reference, the changes you make on one page are lost when you move to another one. There are several ways of sending data between pages, though. Two very common ones are using forms, which can, in turn, generate either GET or POST data. POST data is when the information is sent to the page you specify in a way that is not viewable to the user. GET is what produces the ?variable=value format. One nice thing about GET data, is that you don't need a form to generate it, you can write it yourself if you want.
For example, let's say we want a page that follows a template, and has three links. Each link, when clicked, should reload the page, showing a specific passage of text. To achieve this, we'll use GET data to pass a value to the script, and then we'll let PHP parse the GET data and return a result.
Our HTML for the links will look like this:
Code: Select all
Display: <a href="?page=1">Passage 1</a> <a href="?page=2">Passage 2</a> <a href="?page=3">Passage 3</a>Code: Select all
<?php
$currentPage = $_GET['page']; //our URL's are using GET, with each thing between & being a pair of variable=value
//PHP automatically puts these into an array ($_GET) which lets you access your variable as the array element key.
switch($currentPage){
case '1':
echo 'Congratulations! You are now viewing passage #1!';break; //notice that the case ends with "break;" without which it would also parse case #2
case '2':
echo 'Congratulations! You are now viewing passage #2! Isn\'t this cool?';break; //notice that the ' is escaped (\')
case '3':
echo 'Congratulations! You are now viewing passage #3!';break;
default: echo 'You don't have a passage selected.';
}
?>
Re: Page naming
Hello,
As said above, the extra characters you are noticing in the URL are GET parameters and are used in PHP for a variety of reasons. If you are noticing a website such as: http://www.example.com/?page=test&ext=php I would be willing to bet that the creator of the PHP page accepting that request (which is usually a common script such as index.php) is including files based on the details passed in the URL.
In this case in the PHP file the creator would more than likely have something such as:
I am probably going off a little too far now just in your example I noticed you had HTML in one of the parameters and I thought this may be something the author of the page was attempting, or you could have typed HTML in there as an example and nothing more.
If you need anything at all, just let me know
.
Thanks.
As said above, the extra characters you are noticing in the URL are GET parameters and are used in PHP for a variety of reasons. If you are noticing a website such as: http://www.example.com/?page=test&ext=php I would be willing to bet that the creator of the PHP page accepting that request (which is usually a common script such as index.php) is including files based on the details passed in the URL.
In this case in the PHP file the creator would more than likely have something such as:
Code: Select all
<?php
$whitelist = array();
$whitelist[] = 'test.php';
$page = $_GET['page'] . $_GET['ext'];
if(in_array($page, $whitelist))
{
include $page;
}
If you need anything at all, just let me know
Thanks.