[PHP] Submappen includen via get-string*

Pagina: 1
Acties:
  • 37 views sinds 30-01-2008

  • thebrothers
  • Registratie: Mei 2004
  • Laatst online: 27-07-2025
Hallo, Alleerst ik heb me suf gezocht op het internet en op het GOT forum naar een oplossing, wat ik heb gevonden bracht mij niet tot de oplossing.

Het probleem is als ik een pagina include met een submap gaat het fout, de volgende link geef ik mee in het script:

index.php?page=map/submap/testje

Maar ik krijg de hoofdpagina (zoals ingesteld) weer te zien.
Bij mijn index heb ik het volgende script staan:




$root="..";

if (file_exists($root."/".$_GET["page"].".php"))
{
$inc = $_GET[page];
}
else $inc = "HOOFDPAGINA";
{
include ($inc.".php");
}



Zonder submap werkt alles goed. Ik heb het gevoel dat ik er dicht bij zit.. 8)7

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 15-04 22:07

NMe

Quia Ego Sic Dico.

Welke tekst bevat $root? En staat er wel precies in $_GET['page'] wat je hebben wil?

Gebruik trouwens liever [code] tags als je code wil posten. :)

[ Voor 2% gewijzigd door NMe op 02-05-2005 20:25 . Reden: Scheel ]

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


  • Dutchmega
  • Registratie: September 2001
  • Niet online
Code-tags.. arg! :P
maargoed, bestaat ook "../map/submap/testje.php" dan? Het lijkt me sterk dat PHP dat fout heeft...

offtopic:
Met ../ bedoel ik dan ook de 'parent-map'...


EDIT:

code:
1
2
3
{
include ($inc.".php");
}


Das niet zo goed maar PHP parsed het wel goed.. (denk ik)

[ Voor 57% gewijzigd door Dutchmega op 02-05-2005 20:25 ]


  • GlowMouse
  • Registratie: November 2002
  • Niet online
Kun je mij trouwens uitleggen waarvoor het tweede set accolades dient?

Verwijderd

* knip * ^^ Wat hij zei dus.

[ Voor 76% gewijzigd door Verwijderd op 02-05-2005 20:25 ]


  • T-MOB
  • Registratie: Maart 2001
  • Nu online
-NMe- schreef op maandag 02 mei 2005 @ 20:21:
Welke tekst bevat $root? En staat er wel precies in $_GET['page'] wat je hebben wil?
$root bevat '..', en daar ligt ook het probleem. Want als ../map/submap/file.php bestaat dan include TS "map/submap/file.php" die waarschijnlijk niet bestaat.
PHP:
1
2
3
4
include '../' .$_GET['page'] .'.php';
//of
include '/' .$_GET['page'] .'.php';
//als $root ook idd de webroot is...

Regeren is vooruitschuiven


  • NMe
  • Registratie: Februari 2004
  • Laatst online: 15-04 22:07

NMe

Quia Ego Sic Dico.

Die if/else constructie is helemaal prima (kwa werking) maar ik zou hem zelf nooit zo schrijven. Accolades kun je neerzetten waar je maar wil, die geven alleen een compound statement aan. In dit geval maakt het dus geen fluit uit. :)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


  • NMe
  • Registratie: Februari 2004
  • Laatst online: 15-04 22:07

NMe

Quia Ego Sic Dico.

T-MOB schreef op maandag 02 mei 2005 @ 20:26:
$root bevat '..', en daar ligt ook het probleem. Want als ../map/submap/file.php bestaat dan include TS "map/submap/file.php" die waarschijnlijk niet bestaat.
PHP:
1
2
3
4
include '../' .$_GET['page'] .'.php';
//of
include '/' .$_GET['page'] .'.php';
//als $root ook idd de webroot is...
Argh, duh. :) Gewoon simpel debugwerk dus. :)

@TS: Volgende keer zelf even debuggen. Stop je strings is variabelen en controleer of er wel in staat wat er in moet staan. Lees ook even P&W FAQ - Leer **** debuggen!!. :)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.

Pagina: 1

Dit topic is gesloten.