adamriley Posted December 22, 2009 Share Posted December 22, 2009 Hi my php code is -------------------------------------------------------------- <?php if (isset($_GET['a']) && $_GET['a'] != "") { if (isset($_GET['b']) && $_GET['b'] != "") { $a = $_GET['a']; $b = $_GET['b']; if (file_exists('pages/'.$a.'.$b')) { @include ('pages/'.$a.'.$b'); } elseif (!file_exists('pages/'.$a.'.$b')) { echo 'Page you are requesting doesnt exist'; } } else { @include ('pages/1.php'); } ?> --------------------------------------------- my url is "sitemap.php?a=1&b=php" -------------------------------------------- could you say why its not working im a beginner Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/ Share on other sites More sharing options...
sh0wtym3 Posted December 22, 2009 Share Posted December 22, 2009 What error are you getting? And if you don't see any errors just add: error_reporting(E_ALL); ... to the top of your code. Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982462 Share on other sites More sharing options...
rajivgonsalves Posted December 22, 2009 Share Posted December 22, 2009 for us to help you, you will have to elaborate on whats not working, you must tell us 1) Whats the result 2) What was the expected result Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982463 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 Are you getting any errors? put this at the top of your script.. error_reporting(E_ALL); ini_set('display_errors',1); And remove the @ symbols.. Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982464 Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 ok what i get is "Parse error: syntax error, unexpected $end in /home/a162162/public_html/sitemap.php on line 47" what i expected is the file that was named in the "a=1" and the file format that was "b=php" Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982475 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 you are missing a } at the end of your script.. formatting helps find these things out <?php if (isset($_GET['a']) && $_GET['a'] != "") { if (isset($_GET['b']) && $_GET['b'] != "") { $a = $_GET['a']; $b = $_GET['b']; if (file_exists('pages/'.$a.'.$b')) { @include ('pages/'.$a.'.$b'); } elseif (!file_exists('pages/'.$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/#findComment-982478 Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 This part of the script is now solved but now it seems that it cannot find the page when i try the script with 1 parameter. The script excludes the "Page you are requesting doesnt exist" Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982487 Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 This part of the script is now solved but now it seems that it cannot find the page when i try the script with 1 parameter. The script excludes the "Page you are requesting doesnt exist" Sorry that one is very confusing what i ment is that bit of the script now works but the script now says "Page you are requesting doesnt exist" Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982490 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 You need to simplify the code down a bit.. if (file_exists('pages/'.$a.'.$b')) { @include ('pages/'.$a.'.$b'); } elseif (!file_exists('pages/'.$a.'.$b')) { echo 'Page you are requesting doesnt exist'; } can be simply put as if (file_exists('pages/'.$a.'.$b')) { @include ('pages/'.$a.'.$b'); } else { echo 'Page you are requesting doesnt exist'; } because you already know the page doesnt exist... Here is a cleaner version.. <?php if (isset($_GET['a']) && isset($_GET['b']) && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; if (file_exists('pages/'.$a.'.$b')) { include('pages/'.$a.'.$b'); } else { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php'); } ?> Make sure that your directory structure matches what you are testing for.. Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982493 Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 Hi thanks my directory structure matches what you i am testing for and the script still does not dissplay what i want it to Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982509 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 You could infact ignore that file_exists.. <?php if (isset($_GET['a']) && isset($_GET['b']) && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; if (!@include('pages/'.$a.'.'.$b)) { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php'); } ?> Edit: I just noticed an error which is gone in the code above 'pages/'.$a.'.$b' would be looking for 1.$b Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982519 Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 The script still does not work :confused: Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982525 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 Did you use the last edited version I posted? <?php if (isset($_GET['a']) && isset($_GET['b']) && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; if (!@include('pages/'.$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/#findComment-982526 Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 Ok thanks the script does now work which part of the script did you change Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982536 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 Just 'pages/'.$a.'.$b' to 'pages/'.$a.'.'.$b Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982537 Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 so if i was to add a third parameter what would i need to add Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982549 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 What will the 3rd parameter be for? Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-982584 Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 If i was to add a c parameter to the bit that says "('pages/" and put $c what would the script now be Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-983182 Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 so $c would replace the word pages? Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-983191 Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 yes it would so the url would be something like sitemap.php?a=1&b=php&c=pages Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-983211 Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 then it would be <?php if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['c'] !='' && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; if (!@include($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/#findComment-983214 Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 Thanks very much for your time Buddski Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-983217 Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 Not a problem.. Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-983220 Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 Am i right in thinking you missed "$c = $_GET['c'];" from the script Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-983223 Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 Indeed you are 5am coding is never good.. Link to comment https://forums.phpfreaks.com/topic/186041-php-url-parameter/#findComment-983226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.