View Full Version : In a website that ALL webpages are of index.php?id=1, index.php?id=2, index.php?id=3,
leonidassavvides
05-27-2009, 07:36 AM
In a website that ALL webpages are of index.php?id=1, index.php?id=2, index.php?id=3, index.php?id=4,...... how this mechanism is and work ? are they take markup code from database table fields, by this way ?
JohnDMcQ
05-27-2009, 05:39 PM
They are probably using ajax to replace frames or sections of the page without refreshing the entire page.
leonidassavvides
05-27-2009, 06:18 PM
I mean from home: index.php?id=1 you go to a subpage eg: index.php?id=2 by click ...well ? are they save markup code from database table fields, and visitor retrieves this by surf this way ? If yes, how the developer edits the markup code from database fields, in a WYSIWYG Editor ?
Thats using PHP $_GET, here:
<?php
if(isset($_GET['greeting']) && $_GET['greeting'] == "hi"){
echo "Hello Mr!";
}
?>
Then go to: ?greeting=hi
leonidassavvides
05-27-2009, 07:38 PM
I know this I wanted to learn if: involves Database? how appear the field(markup code)?is it encoded this TEXT Database data ? How edit code database TEXT fields, in a WYSIWYG Editor ?
it can involve a database, but it isn't necessary. If it is fairly static content (meaning not something like a blog or something else you need a DB for), it would be easier to code like this (using php):
<php
if (!isset ($_GET['id'])){ //if no GET data present, load the default page content
include "path/to/default/content.php";
} else { //otherwise, use the GET 'id' to load the desired content
$page = $_GET['id'];
include "path/to/content/page".$page.".php"; //e.g., if the url is "index.php?id=1"
//this will load the content from your external file named "page1.php" into index.php.
}
?>
Well, first of all, its <?php not <php. Second there is a huge security whole with that script and that is that if an htaccess file is protecting something, it can bypass that protection.
Sorry about the typo!
Could the hole be fixed by matching the GET info to a predefined list? Something like this:
<?php
if (!isset ($_GET['id'])){ //if no GET data present, load the default page content
include "path/to/default/content.php";
} else { //otherwise, use the GET 'id' to load the desired content
$GETpage = $_GET['id']; //variable to store GET page id
$OKpages = array ('page1', 'page2', 'page3'); //list of valid options
$page = null; //make sure nothing is selected by default
foreach ($OKpages as $OK) { //loop over OKpages array
if ($GETpage == $OK){ //if one matches the GET page id,
$page = $GETpage; //use that as the page to load
include "path/to/content/".$page.".php"; //e.g., if the url is "index.php?id=page1"
//this will load the content from your external file named "page1.php" into index.php.
break; //and stop comparing
} else { //if there's no match,
echo 'You Are Lost!'; //they're trying to visit a restricted or non-existent page
include "path/to/sitemap"; //tell them where they *can* go
}
}
}
?>
Tested code and made corrections as to line order; also corrected <php typo that I accidentally copied from my post above :rolleyes:
thetestingsite
05-30-2009, 03:09 AM
Instead of the foreach, you should use in_array(). Something like the following should work:
<php
if (!isset ($_GET['id'])){ //if no GET data present, load the default page content
include "path/to/default/content.php";
}
else { //otherwise, use the GET 'id' to load the desired content
$pages = array ('page1', 'page2', 'page3'); //list of valid options
if (in_array($_GET['page'], $pages)) {
include('/path/to/'.$_GET['page']);
}
else { //if there's no match,
echo 'You Are Lost!'; //they're trying to visit a restricted or non-existent page
include "path/to/sitemap"; //tell them where they *can* go
}
}
}
?>
Not tested and this really does depend on the way you have everything set up, but should work nontheless.
Hope this helps.
leonidassavvides
05-31-2009, 08:47 PM
is it encoded this TEXT Database data ? I MEAN SPECIAL CHARACTERS[FOR DB] APPEAR AS IS HENCE WE HAVE "text" db field type ?
^my example (and thetestingsite's alternative above) do not use a database at all, so no, there is no "encoding" (inserting, retrieving, updating, etc.) for a database.
molendijk
06-01-2009, 12:12 AM
You can do something similar using javascript, see this (http://www.dynamicdrive.com/forums/blog.php?bt=64).
===
Arie Molendijk.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.