corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Template Help


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP Template Help
Laney
Member

Registered: 6th May 03
Location: Leeds
User status: Offline
9th Jul 07 at 19:20   View User's Profile U2U Member Reply With Quote

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
9th Jul 07 at 20:16   View User's Profile U2U Member Reply With Quote

You've not done a get?

$section = $_GET['section'];
Laney
Member

Registered: 6th May 03
Location: Leeds
User status: Offline
9th Jul 07 at 20:50   View User's Profile U2U Member Reply With Quote

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
9th Jul 07 at 22:34   View User's Profile U2U Member Reply With Quote

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
10th Jul 07 at 17:43   View User's Profile U2U Member Reply With Quote

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
10th Jul 07 at 17:47   View User's Profile U2U Member Reply With Quote

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
10th Jul 07 at 17:56   View User's Profile U2U Member Reply With Quote

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
10th Jul 07 at 18:32   View User's Profile U2U Member Reply With Quote

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
10th Jul 07 at 18:32   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
10th Jul 07 at 18:35   View Garage View User's Profile U2U Member Reply With Quote

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
10th Jul 07 at 22:58   View User's Profile U2U Member Reply With Quote

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
17th Jul 07 at 07:50   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
17th Jul 07 at 19:00   View Garage View User's Profile U2U Member Reply With Quote

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
17th Jul 07 at 19:10   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
17th Jul 07 at 19:26   View Garage View User's Profile U2U Member Reply With Quote


 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
CV Templates? Foz General Chat 2 569
19th Sep 03 at 18:11
by Foz
 
Stupid DIY tool Q Valleyscorsa House Day 8 855
4th Aug 04 at 19:05
by Valleyscorsa
 
New Corsa C bodykit Dave_Gordon Help Zone, Modification and ICE Advice 2 648
25th Jan 05 at 19:27
by Dave_Gordon
 
rear mesh around exhaust corsa_griff Help Zone, Modification and ICE Advice 4 915
30th Mar 06 at 17:56
by jake
 
Anyone know PHP? Bit of help needed... liamC Geek Day 38 1449
24th Nov 06 at 23:02
by MarkPW
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Template Help 28 database queries in 0.0119410 seconds