Jump to content
php.lv forumi

include


Atomz

Recommended Posts

<a href="?x=kautkas">kautkas</a>
<a href="?x=nezinu_kas">nezinu_kas</a>

<?php include($_GET['x']); ?>

 

Tikai silti iesaku validēt to $_GET['x'] pirms izmantošanas. Es darītu šādi:

$valid_includes = array(
'kautkas' => 'kautkas.php',
'nezinu_kas' => 'nezinu_kas.php'
)

if (!empty($_GET['x']) && isset($valid_includes[$_GET['x']])) {
include($valid_includes[$_GET['x']]);
}

 

Kaut kā tā.

Edited by andrisp
Link to comment
Share on other sites

Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.;C:\php5\pear') in C:\AppServ\www\Tests\index.php on line 14

 

a 14 līnijā man ir šitas: <?php include($_GET['x']); ?>

 

tipa pēc manām domām vajadzētu kautko līdzīgu kā default priekš tā x noteikt, bet KĀ? :)

Link to comment
Share on other sites

šitam galā varētu pielikt:

$valid_includes = array(
'kautkas' => 'kautkas.php',
'nezinu_kas' => 'nezinu_kas.php'
)

if (!empty($_GET['x']) && isset($valid_includes[$_GET['x']])) {
include($valid_includes[$_GET['x']]);
}
else {
$_GET['x'] = 'defaultaa_lapa';
//include bla bla bla
}

Link to comment
Share on other sites

×
×
  • Create New...