View Full Version : page within a page?
sabret00the
10-31-2003, 01:30 PM
if i've got a page that does what it's meant to do, how do i go about making it have &page=whatever ?
would i need to enclose it all in a switch function or can i add some sort of if statement?
NTLDR
10-31-2003, 01:37 PM
It really all depends how you want it to work, for example:
<?php
require('./global.php');
eval("dooutput(\"".gettemplate($page)."\");");
?>
Thats the basic code for vB2 to get a page based on file.php?page=pagename you could also have a switch/if block to change between a pre-defined set of pages.
sabret00the
10-31-2003, 01:43 PM
hmm, sorry a little confused, this is my first attempt at a vB hack really
basically i got a bunch of code on the page which calls how the main page looks but i wanna add main.php&page=rules
would i just add that into the bottom of the main script?
Velocd
10-31-2003, 01:57 PM
You're being vague still.
The parameters in a URL, which are variables, can be used in php like this:
if($_GET['page'] == 'rules')
{
// code here
}
NTLDR
10-31-2003, 01:58 PM
Assuming you already have all the PHP in place to do the main page, all you would need is somthing like:
eval("\$content = \"".gettemplate("mypage_{$page}")."\";");
Where $page is whats in the URL (x.php?page=rules), you need to make sure this goes above the dooutput line you'll have that would look similar to the one I posted above. In your main template, add $content where you want the content of the template to go. Note the mypage in the above line, I'd recommend using a prefix to prevent users looking at templates they shouldn't :)
sabret00the
10-31-2003, 02:16 PM
<?php
error_reporting(7);
$templatesused = 'confessions,confessionbit,confession_adminoptions ,confession_error,confession_pagenav,confession_le ftside';
require("./global.php");
// all the code that makes the page work
if($_GET['page'] == 'privacy')
{
eval("\$content = \"".gettemplate("confessionprivacy")."\";");
}
?>
i know that aint right cos it don't work but something like that?
filburt1
10-31-2003, 02:20 PM
require_once("./global.php");
switch ($_GET['show'])
{
case "something":
eval("dooutput(\"" . gettemplate("sometemplate") . "\");");
break;
case "somethingelse":
eval("dooutput(\"" . gettemplate("someothertemplate") . "\");");
break;
}
sabret00the
10-31-2003, 02:57 PM
i thought i would've ended up doing something like that, thanks filburt
arghhh, i suck at php, this is what i tried
switch ($_GET['show'])
{
case "privacy":
eval("dooutput(\"" . gettemplate("confession_privacy") . "\");");
break;
case "confess":
eval("dooutput(\"" . gettemplate("confession_confess") . "\");");
break;
default:
eval("
$confessions = $DB_site->query("SELECT confessionid, text, timestamp FROM confessions $clause ORDER BY confessionid DESC $limit");
if (!$DB_site->num_rows($confessions)) {
eval("\$confessionbits = \"".gettemplate("confession_error",1,0)."\";");
}
else {
while ($confession_info = $DB_site->fetch_array($confessions)) {
extract($confession_info);
$color = ($num++ % 2 == 0) ? '{firstaltcolor}' : '{secondaltcolor}';
$totalconf = number_format($DB_site->num_rows($confessions));
$time_posted = vbdate('n-j-y, g:i:s a', $timestamp);
$text = bbcodeparse($text);
if ($bbuserinfo[usergroupid] == 5 || $bbuserinfo[usergroupid] == 6 || $bbuserinfo[usergroupid] == 7) {
eval("\$adminoptions = \"".gettemplate("confession_adminoptions",1,0)."\";");
}
eval("\$confessionbits .= \"".gettemplate("confessionbit",1,0)."\";");
}
}
");
break;
}
can't get to work
sabret00the
10-31-2003, 04:20 PM
*bump plea for help*
Dean C
10-31-2003, 06:31 PM
You might want to remove that big eval(" ") around everything :)
Velocd
10-31-2003, 11:26 PM
Sabret, I think you are in need of some PHP tutorials (such as http://www.php.net/manual/en/). That's just incorrect usage of the eval function:
http://www.php.net/eval
If you are ever in need of knowing how a PHP function works, consult the function search at PHP.net. Best resource.
For that code, strip the last eval, leaving that big chunk of code separate. Then remove the last two breaks, since the last break in a switch statement is unnecessary.
Dean C
11-01-2003, 09:44 AM
I also think it would be be benefitial in this instance to use if statements instead of a switch. Switch is useful for small little blocks of code but IMO when you have large chunks like that it's best to go with an if statement :)
sabret00the
11-01-2003, 09:55 AM
on a site i done where i was just using php to recall headers,footers and main table i didn't have the eval stuff and it worked but tried this with and without the eval stuff and don't work, off out to go get a book on php tho :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.