Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
code:
<?php
if(!isset($section))
{
$section="list_gigs";
}
$section .= ".php";
echo $section;
require 'config.php';
require 'opendb.php';
require 'header.php';
require $section;
require 'footer.php';
?>
Bit stuck as to why this won't take the $section variable through the browser. As in index.php?section=view
Gotta be something obvious but I've got syntax-blindness
|
James
Member
Registered: 1st Jun 02
Location: Surrey
User status: Offline
|
You've not done a get?
$section = $_GET['section'];
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by James
You've not done a get?
$section = $_GET['section'];
Time to put the code away me thinks
|
MikeLamb
Member
Registered: 23rd Sep 03
Location: Crowthorne Drives: Veccy SRI
User status: Offline
|
What you did would have worked in older versions of PHP..
|
poole
Member
Registered: 12th Oct 03
Location: Sheffield, UK Drives: 2.5 v6 Calibra
User status: Offline
|
quote: Originally posted by MikeLamb
What you did would have worked in older versions of PHP..
Nah, its just that register_globals (the php settings variable is set by default to off in newer versions. Can't remember the exact version this changed at but it was a while ago).
Little example that should help.
code:
<?php
require_once('config.php');
require_once('opendb.php');
require_once('header.php');
// gets url.com/file.php?section=bleh
switch ($_GET['section']) {
case "main":
include_once('main.php');
break;
case "example":
include_once('example.php');
break;
default:
include_once('gigs.php);
}
require 'footer.php';
?>
Just create a case block for every eventuality.
[Edited on 10-07-2007 by poole]
|
poole
Member
Registered: 12th Oct 03
Location: Sheffield, UK Drives: 2.5 v6 Calibra
User status: Offline
|
BTW i'm not using the same method as yourself (taking any user input) for security reasons.
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by poole
BTW i'm not using the same method as yourself (taking any user input) for security reasons.
I was thinking a Switch might make it safer
|
drax
Member
Registered: 5th Feb 05
Location: Sittingbourne, Kent
User status: Offline
|
Try this
code: $page = $_GET["p"];
if (($page =="")) {include('pages/page1.php');
} else if($page == 'Page1') { include('pages/page1.php');
} else if($page == 'Page2') { include('pages/page2.php');
} else if($page == 'Page3') { include('pages/page3.php');
} else if($page == 'Page4') { include('pages/page4.php');
} else {include('pages/error.php');
}
/code]
Your links would look like this..
code: <a href="?p=Page1" title="Link to page 1">This is a link</a>
|
drax
Member
Registered: 5th Feb 05
Location: Sittingbourne, Kent
User status: Offline
|
The above is a crude but effective way of doing it, theres a better way to do it but its more complex to write and understand
[Edited on 10-07-2007 by drax]
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Offline
|
Yes - you must must must not append .php to the end of some user input and call that a filename.
FAR safer to say -
if var == main then page == main.php
if var == gigs then page == gigs.php
Either a switch or if you're feeling nifty make an array of strings to test and and array of filenames, in the same order so they share array index.
Then you just foreach through that and set your page address variable out of your filename array.
Hope that is clear enough haha
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by Ian
Yes - you must must must not append .php to the end of some user input and call that a filename.
FAR safer to say -
if var == main then page == main.php
if var == gigs then page == gigs.php
Either a switch or if you're feeling nifty make an array of strings to test and and array of filenames, in the same order so they share array index.
Then you just foreach through that and set your page address variable out of your filename array.
Hope that is clear enough haha
Gotcha
Thanks Geekday
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
Hmmm, I'm still having problems with this.
I've set up a switch for the $section which seems to work fine until I add another variable to the string ie,
?section=email&action=send
That shouldnt really cause a problem should it?
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Offline
|
Shouldn't do, would just mean that your $_GET[] array has more stuff in it.
If you're switching on $_GET['section'] as poole suggested then should work?
What are the symptoms?
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
Ok, it seems to be working now?! I think I'd set the switch up incorrectly No more syntax questions I promise
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Offline
|
|