index.php
Moderator: General Moderators
index.php
Hello,
Does anyone know a good tutorial on working with page ID's?
What I want is that my site is :
index.php?pid=1
index.php?pid=2
And that the pageid determines the content.
I saw an example with different file inclusions, but I want the ID's to be linked to different rows in my MySQL database, so instead of file inclusions a connection to my database.
anyone?
Does anyone know a good tutorial on working with page ID's?
What I want is that my site is :
index.php?pid=1
index.php?pid=2
And that the pageid determines the content.
I saw an example with different file inclusions, but I want the ID's to be linked to different rows in my MySQL database, so instead of file inclusions a connection to my database.
anyone?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
You are looking at creating a page controller. This is fairly easy to do. It is code intensive at first, but once it is done adding pages to your site is a snap. As for tutorials, I haven't seen any, but I am sure with a little thought and a few trials and errors, you'll it. I say give it a shot and post when things go horribly awry.
already got it I think.
on top of the page
and
where I want it to be 
Works!
Code: Select all
$pageid = isset($_GET['pid']) ? $_GET['pid'] : 'page1';and
Code: Select all
$result = mysql_query("SELECT * FROM tblContent WHERE page='$pageid' AND username='$localuser' ")Works!
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
You can create a page controller quite easily:
(at least i think that qualifies)
Code: Select all
$page = !empty($_GET['pid']) ? $_GET['pid'] : 'default';
if (@!include_once("content/$page.php"))
{
echo "Page not found.";
}
Last edited by daedalus__ on Thu Jul 20, 2006 11:18 am, edited 1 time in total.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
*PURPLE ALERT* *PURPLE ALERT*Daedalus- wrote:You can create a page controller quite easily:
(at least i think that qualifies)Code: Select all
$page = !empty($_GET['pid']) ? $_GET['pid'] : 'default'; if (@!include_once("content/$page.php")) { echo "Page not found."; }
That code is asking for trouble. Sanitise input please .. don't let user's include *everything*.
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
No War!thiscatis wrote:already got it I think.
on top of the pageCode: Select all
$pageid = isset($_GET['pid']) ? $_GET['pid'] : 'page1';
and
where I want it to beCode: Select all
$result = mysql_query("SELECT * FROM tblContent WHERE page='$pageid' AND username='$localuser' ")
Works!
Like I mentioned above, I got it working my way
Thanks for the input guys
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Remember filtering, validation, and error checking.
Code: Select all
if (isset($_GET['pid'])) {
$pageid = preg_replace('/[^a-zA-Z0-9\_]/', '', $_GET['pid']); // delete chars NOT in that set
} else {
$pageid = 'page1';
}
if ($localuser) {
$result = mysql_query("SELECT * FROM tblContent WHERE page='$pageid' AND username='$localuser' ")
if (mysql_num_rows() > 0) {
// query successful
} else {
// query error
}
} else {
// user error
}
// display page based on above(#10850)