|
Ian
|
posted on 17th Jul 07 at 19:26 |
:D
|
Laney
|
posted on 17th Jul 07 at 19:10 |
Ok, it seems to be working now?! I think I'd set the switch up incorrectly :o No more syntax questions I promise :D
|
Ian
|
posted on 17th Jul 07 at 19:00 |
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
|
posted on 17th Jul 07 at 07:50 |
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?
|
Laney
|
posted on 10th Jul 07 at 22:58 |
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 :D
Thanks Geekday ;) :o :lol:
|
Ian
|
posted on 10th Jul 07 at 18:35 |
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
|
drax
|
posted on 10th Jul 07 at 18:32 |
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]
|
drax
|
posted on 10th Jul 07 at 18:32 |
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>
|
Laney
|
posted on 10th Jul 07 at 17:56 |
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 :thumbs:
|
poole
|
posted on 10th Jul 07 at 17:47 |
BTW i'm not using the same method as yourself (taking any user input) for security reasons.
|
poole
|
posted on 10th Jul 07 at 17:43 |
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]
|
MikeLamb
|
posted on 9th Jul 07 at 22:34 |
What you did would have worked in older versions of PHP..
|
Laney
|
posted on 9th Jul 07 at 20:50 |
quote: Originally posted by James
You've not done a get?
$section = $_GET['section'];
:rolleyes:
Time to put the code away me thinks :(
|
James
|
posted on 9th Jul 07 at 20:16 |
You've not done a get?
$section = $_GET['section'];
|
Laney
|
posted on 9th Jul 07 at 19:20 |
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 :(
|