adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 Its ok it does not matter it 6.15pm were i am Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983227 Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 Just for the last question if i wanted to change the parameter "$c" to a number and have the script see the number and change it to a folder for example the url would be "sitemap.php?a=1&b=php&c=1" the c parameter would relate to a folder for example "pages" then the script would show the file "pages/1.php" if to confussing just say and i will try and word it in a way you understand Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983255 Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 I think I understand let me throw this at ya.. <?php $directories = array(1=>'pages'); if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['c'] !='' && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; $c = $_GET['c']; if (!isset($directories[$c]) && !@include($directories[$c].'/'.$a.'.'.$b)) { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php'); } ?> Then all you have to do is create different associations in the directories array like $c being 4 might point to images. so you would add $directories = array(1=>'pages',4=>'images'); // or $directories = array(); $directories[1] = 'pages'; $directories[4] = 'images'; Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983261 Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 Yes i do 100% Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983271 Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 it does not work a blank screen url is "?a=1&b=php&c=1" is it right <?php $directories = array(1=>'pages'); if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['c'] !='' && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; $c = $_GET['c']; if (!isset($directories[$c]) && !@include($directories[$c].'/'.$a.'.'.$b)) { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php');} ?> Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983281 Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 <?php $directories = array(1=>'pages'); if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['c'] !='' && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; $c = $_GET['c']; if (isset($directories[$c])) { if (!@include($directories[$c].'/'.$a.'.'.$b)) { echo 'Page you are requesting doesnt exist'; } } else { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983287 Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 It works now thanks very very much! Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983292 Share on other sites More sharing options...
laffin Posted December 23, 2009 Share Posted December 23, 2009 Something like this should work // Setup our paths, 0 is always default $directories = array(0=>'pages',1=>'images'); // Get First parameter, if non-existant or empty, set default to '1' $a=isset($_GET['a'])?(!empty($_GET['a']?$_GET['a']:'1'):'1'; // Get Second parameter, if non-existant or empty, set default to 'php' $b=isset($_GET['b'])?(!empty($_GET['b']?$_GET['b']:'php'):'php'; // Get Third Paramter, if non-existant or empty, set default to 0 // if not in array of pages set default $c=isset($_GET['c'])?(!empty($_GET['c']?(isset($directories[$_GET['c']]?$_GET['c']:0):0):0; // Check if the page exists, if not show error if(!file_exists($page="{$directories[$c]}/{$a}.{$b}")) { echo 'Page you are requesting doesnt exist'; } else { // Otherwise grab the page @include($page); } Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983296 Share on other sites More sharing options...
adamriley Posted December 24, 2009 Author Share Posted December 24, 2009 I think i will stick with Buddski's one as im a new to php and i understand his one Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/page/2/#findComment-983741 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.