Kemito Posted October 1, 2009 Report Share Posted October 1, 2009 Tā tad sekojoši: if($GET['lapa']) { if(file_exists($GET['lapa'].".php")) { include($GET['lapa'].".php"); } else { include('nav.php'); } } Ideja ir sekojoša varbūt kādam ir priekšlikums vai koda gabals ar kuru var panākt iznākumu! index.php?lapa=mansfails Izveidojot failu mansfails.php Respektīvi izveidoju failu fails.php tad līdz ar to būs index.php?lapa=fails Ceru, ka sapratāt! Viens cilvēks teica ka šāds risinājums nav labs: Citāts no viņa teiktā: nedrīkst šādi caur getu padot parametru pēc kura nosaka inklūdējamā faila nosaukumu Paldies! Quote Link to comment Share on other sites More sharing options...
waplet Posted October 1, 2009 Report Share Posted October 1, 2009 pag pag pag ko tad tu īsti gribi? Quote Link to comment Share on other sites More sharing options...
Kemito Posted October 1, 2009 Author Report Share Posted October 1, 2009 Lapu lapiņā! http://cashos.com/index.php?lapa=forum Reāli lūk piemērs! ?lapa=manafailanosaukums Ja ir izveidots manafailanosakums.php fails tad šādi būs ja peiprasītā lapiņa nebūs teiksim man nav fails asd tad inklūdosies nav.php ja būs asd.php tad būs ?lapa=asd ;) Quote Link to comment Share on other sites More sharing options...
ohmygod Posted October 1, 2009 Report Share Posted October 1, 2009 Risininājums nav labs, ja nepārbaudi, ko lietotājs raksta. Ja ir nodefinēti atļautie faili un notiek pārbaude - vari tā darīt. Lai gan... Ir labāki veidi kā zināt, kas jāinklūdo... Un kāpēc jāinklūdo? Tas patiešām ir nepieciešams? Quote Link to comment Share on other sites More sharing options...
Kemito Posted October 1, 2009 Author Report Share Posted October 1, 2009 Saprotu, bet man sanāca tomēr! :) Quote Link to comment Share on other sites More sharing options...
waplet Posted October 1, 2009 Report Share Posted October 1, 2009 (edited) ņem index.php $pg=$_GET['lapa']; if (!isset($pg)){ $pg='news'; } if (file_exists("lapas/".$pg.".php")) { include("lapas/".$pg.".php"); } else{print"<div class=\"msg-error\"><ul><li>Not Found.</li></ul></div>"; } m_protect.inc.php <?php if(!isset($pg)){ Die("Wrong Page!"); } ?> un iekš tiem sub failiem <?php include"m_protect.inc.php"; ?> Edited October 1, 2009 by waplet Quote Link to comment Share on other sites More sharing options...
Kemito Posted October 1, 2009 Author Report Share Posted October 1, 2009 waplet - nebūs par garu? Man ir sekojoši: <?php if(isset($_GET['lapa'])) { if(file_exists($_GET['lapa'].".php")) { include($_GET['lapa'].".php"); } else { include('nav.php'); } } ?> Quote Link to comment Share on other sites More sharing options...
waplet Posted October 1, 2009 Report Share Posted October 1, 2009 sit ķēpā un klapējat ciet šo topiku Quote Link to comment Share on other sites More sharing options...
ziemelis Posted October 1, 2009 Report Share Posted October 1, 2009 Waplet, un kas notiks, ja es padošu "?lapa=../config.php" Tā vis neies cauri, vajag filtrēt Quote Link to comment Share on other sites More sharing options...
Kemito Posted October 1, 2009 Author Report Share Posted October 1, 2009 Waplet man? skrien taisni un klapē tik ciet! Moderi - savu dabūju paldies! :) Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted October 2, 2009 Report Share Posted October 2, 2009 (edited) <?php $pg = $_GET['pg']; if(isset($_GET['pg'])&&$_GET['pg'] != "") { if(file_exists('folderis/folderis/'.$pg.'.php')) { include('folderis/folderis/'.$pg.'.php'); } } else {include('folderis/folderis/bazaars.php'); } ?> Linku nosaukumus liec "?pg=kautkas" Attieciigi arii mapes taisi folderis/folderis, kur buus datu faili. Piemeeram ir index.php, shajaa failaa liec to skriptu. Tad uztaisi linkus, piemeram 3 linki -Par mani, kuram links ir "?pg=about", Pakalpojumi, kuram links ir "?pg=services" un Kontakti, kuram links ir "?pg=contacts". Taatad pie index.php staav mape ar nosaukumu "folderis" un ieksh taas mapes ir veelviena mape ar nosaukumu "folderis", kuraa glabaajas faili ar nosaukumiem contacts.php, services.php un about.php. Neder? tad attieciigi arii buus blaablaa.php?pg=kautkas adrese. Vari meegjinaat lietot arii .htaccess vai MOD Rewrite. Edited October 2, 2009 by MCWeb.lv Quote Link to comment Share on other sites More sharing options...
marcis Posted October 2, 2009 Report Share Posted October 2, 2009 Kur ir problēma uztaisīt masīvu? $includes = array( '' => 'home.php', 'forum' => 'forum.php', 'contacts' => 'contacts.php' ); $include = (!empty($_GET['pg']) && array_key_exists($_GET['pg'])) ? $_GET['pg'] : ''; include($includes[$include]); Quote Link to comment Share on other sites More sharing options...
waplet Posted October 2, 2009 Report Share Posted October 2, 2009 Waplet, un kas notiks, ja es padošu "?lapa=../config.php" Tā vis neies cauri, vajag filtrēt domā kaut kas izvadīsies, ja iekš config nav echo? Quote Link to comment Share on other sites More sharing options...
ziemelis Posted October 2, 2009 Report Share Posted October 2, 2009 nu tas ta ka piemers, array neslikta lieta salikt Quote Link to comment Share on other sites More sharing options...
briedis Posted October 2, 2009 Report Share Posted October 2, 2009 Es ar šitādu apstrādāju inklūdojamo get'u function getSafeIncludePath($str){ $str = trim($str); $invalidChars = array("/",".","\\","\"",";"); return str_replace($invalidChars,"",$str); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.