index.php?id=thuis vraag

Status
Niet open voor verdere reacties.

headout

Terugkerende gebruiker
Lid geworden
30 okt 2000
Berichten
2.939
Ik gebruik dit (simpele) scriptje.
PHP:
<? 
if($id == "") {  
include("thuis.php");  
}  
else {  
if(file_exists("$id.php")) {  
include("$id.php");  
}  
else {  
include("404.php");  
}  
}  
?>

Maar dit script schijnt niet te werken voor bestanden die geinclude worden en wat groter (>8kb) zijn.
Klopt dit?
 
Zit een beetje raar in mekaar moet ik zeggen. Dit is overzichtelijker (en werkt iig gewoon):

PHP:
switch ($id) {
    case nieuws:
        include("nieuws.php");
        break;
    case downloads:
    	include("downloads.php");
    	break;
    case misc:
    	include("misc.php");
    	break;
    default:
		include("home.php");
		break;
}
Deze is ook beter aan te passen:
PHP:
    case voorbeeld:
    	include("eenhelelangebestandsnaam.php");
    	break;
 
Bovenstaande script moet je zeker nooit gebruiken.

Mensen kunnen namelijk misbruik maken van deze code, door de code vanaf een andere site te includen.

( $id = "http://bozeserver.com/foutscript")

PHP kan namelijk de code vanaf een andere locatie includen.

Het foute script zou bijvoorbeeld de hele site kunnen deleten.
 
Geplaatst door admin
Bovenstaande script moet je zeker nooit gebruiken.
Heb je dan een voorbeeld van een script wat ik wel kan gebruiken?
 
Ik heb het idee dat je met $_GET['id'] moet werken...
PHP:
<? 
if(empty($_GET['id']))  
	include("thuis.php");   
else 
{  
	if(file_exists($_GET['id'].".php"))  
		include($_GET['id'].".php");  
	else  
		include("404.php");  
}  
?>
 
Geplaatst door chrisgeerdink
Ik heb het idee dat je met $_GET['id'] moet werken...
Dat had je goed gedacht! :D

Begrijp ik het script als ik zeg:

wordt er niet voor een ide gekozen, dan wordt thuis.php uitgelezen.
Kiest men wel voor een id, bijvoorbeeld informatie, dan wordt informatie.php uitgelezen. kiest men voor een ide die niet bestaat dan krijgt men de 404.php te zien.

Klopt dit? (Want dan snap ik het script en dat vind ik wel zo praktisch :D )
 
PHP:
<? 
if(empty($_GET['id'])) // Als id leeg is dan... 
    include("thuis.php"); // 
else // als id niet leeg is dan....
{  
    if(file_exists($_GET['id'].".php")) // als het bestand wel bestaat dan...
        include($_GET['id'].".php");  
    else  // als het bestand niet bestaat dan...
        include("404.php");  
}  
?>

Trouwens, je kunt ook checken met if(!IsSet($_GET['id'])) ipv if(empty($_GET['id']))
 
Geplaatst door admin
Mensen kunnen misbruik maken van deze code, door de code vanaf een andere site te includen.

( $id = "http://bozeserver.com/foutscript")

Dat is gefixed in de nieuwere versies van PHP :p
 
http://nl.php.net/include/
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using an URL (via HTTP or other supported wrapper - see Appendix I for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using an URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
Maar:
lordwo_NOSPAM_ at laposte_NOBOTS_ dot net 06-Jun-2003 11:42
For users that absolutely want to include($_GET["something"]). As said above by many peaple, it's a very bad idea because of the security issues it brings.
A simple way to correct this (even for novice users) is to implement a switch, referring to all your scripts :
(That supposes that you already know the script names you will include...)
Exemple:
========
switch ($_GET["pagetoinclude"]) {
   case "tomatoes":
   include("tomatoes.php");
  break;
   case "apples":
  include("apple.php");
   break;
   default:
  include("error.php?msg=Bad-Parameter");
}
End of exemple
============
This way, you won't have any bad surprises with kiddies playing with arguments.
(Hope this helps)
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan