Hey all, I've been slowly learning PHP and using it for my website, but I was wondering about something I've seen alot of lately, with PHP and even ASP, and thats page fetching I assume.
Like using PHP code to fetch web pages on your domain right?
I was wondering where I could find some information or maybe an example code and how to go about setting it up.
and what I'm talking about is like when you goto the index page of a website and its like http://www.domain.com/index.php and when you click a page
http://www.domain.com/page.php?=colors
http://www.domain.com/page.php?=coats&fur=black
stuff like that. So if you could tell me what its actually called, because google is unhelpful unless you know what your talking about then I'd really appreciate that thnx!!
Get or fetch pages with PHP
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Get or fetch pages with PHP
I think you mean URL parameters. Those are passed after the domain name, path info and script name. You put a ? followed by name=value pairs separated with &. You can get the values passed with $_GET superglobal variable. See the manual:
http://www.php.net/manual/en/reserved.variables.get.php
http://www.php.net/manual/en/reserved.variables.get.php
(#10850)
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Get or fetch pages with PHP
That can be done a number of ways. Most commonly, it is done by "including" files or using the database.
The URL examples you give have query strings with variables on it. PHP can access those variables via the $_GET array when the page is accessed. That data can be used to determine which page/data to display.
Imagine a URL like "http://doman.tld/page.php?page=index"
To do with includes:
To do with database data:
The URL examples you give have query strings with variables on it. PHP can access those variables via the $_GET array when the page is accessed. That data can be used to determine which page/data to display.
Imagine a URL like "http://doman.tld/page.php?page=index"
To do with includes:
Code: Select all
$validPages = array('index', 'foo', 'bar');
if (in_array($_GET['page'], $validPages) {
include $_GET['page'] . '.php';
} else {
echo "Invalid page.";
}Code: Select all
$result = mysql_query("SELECT `content` FROM `pages` WHERE `title` = '" . mysql_real_escape_string($_GET['page']) . "'");
if ($page = mysql_fetch_object($result)) {
echo $page->content;
} else {
echo "Invalid page.";
}Re: Get or fetch pages with PHP
Ok I think I get it now, yeah I'm gonna have to read up on this, it seems easier to manage pages like this on a larger site.