apple 0 Report post Posted March 13, 2007 While dealing with such a links in php page.php?id=1i dont want that someone access this page directly using page.php..i can give some custom message incase someone try to access page like:page.php okay i can make it by using if condition etc..but the other problem is that, if someone try to access like, page.php?id= in this case (where id is not given, but there's only "?id= " which makes no sense.. in that case i want to make some custom msg etc. how i can handle this situation?Regards Share this post Link to post Share on other sites
matak 2 Report post Posted March 13, 2007 maybe u should try using .htacces, for redirecting page.php to another page. i really don't know proper code to do that but someone else here might know (i'm also interested in that .htaccess code ) Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted March 13, 2007 One method is to define an array of suitable values. In the following snippet, I have defined an array which I use on a small site. $data_array = array('index', 'one', 'two', 'three', 'four', 'five', 'contact'); And then I use the following block of code to make sure the "?page=" contains one of those array elements or they get redirected to the index.php page.Your example uses "?id=", so you will need to modify that. And also, this code block needs some further security added to it, and as you can tell, I include files with ".txt" file extensions. (Included files always parse as html. Add the php tags inside them if they contain php code) The file extensions will need to be altered to the file extension you use. Small changes, really.$submit = $_GET ;echo $_GET ; // echo to confirm the value as a test onlyif( !isset($_GET ) ) { // page is not set , use first array element if (file_exists($data_array[0] . '.txt' )) { include ( $data_array[0] . '.txt' ); } else { include ('index.txt'); // or default to index page if first file doesn't exist } } elseif (in_array($submit , $data_array)) { // value is in array if (file_exists($submit . '.txt' )) { // and exists include ( $submit . '.txt' ); } else { include ('index.txt'); // default to index page } } else { // value is not in array if (file_exists($data_array[0] . '.txt' )) { // and first array name exists include ( $data_array[0] . '.txt' ); } else { include ('index.txt'); // or use index page } } If you follow the script logic, the default page which is included is the index page. Other values must be contained in the defined array.As you add pages, simply add an element to the array defined above.There are other methods to use, just thought you might like to see this one and I had it handy. Hope this helps. Share this post Link to post Share on other sites
galexcd 0 Report post Posted April 13, 2007 When checking the variable ID, are you using the isset function or are you checking if the string == ""?Using string=="" should work if ?id= is enterned and no number. Share this post Link to post Share on other sites
mahirharoon 0 Report post Posted November 28, 2007 (edited) this is the correct code  <?php $variable = $_GET['id'];switch($variable) {default: include('home.php'); break;case "forum": include('forum.php'); break;}?>instructions: case "forum": include([u]'forum.php'[/u]); break; = change - forum.php to the url forum - change to your id (underlined) which will come in index.php?id=[u]forum[/u] $variable = $_GET['id']; -change id to what you want here (underlined) index.php?id=123 Edited December 2, 2007 by mahirharoon (see edit history) Share this post Link to post Share on other sites
pop 0 Report post Posted November 30, 2007 what happens if case isn't forum? if it si something else. will it for sure go to default value, or ?thanks Share this post Link to post Share on other sites
rvalkass 5 Report post Posted November 30, 2007 If it can't find a case to match the value in the variable, it will display everything in the default section. So, with the example above, if $variable is not equal to forum then the default case is displayed.Personally I would put the default case last. I'm not sure if it makes a difference but it seems to be pretty much standard, unless you are using the fall-through method. Share this post Link to post Share on other sites
online 0 Report post Posted December 21, 2007 <?php>if {get=[id=1]}else{header location = page.php?>something like that ....(sorry for my php scripting...i had a bit of hurry) Share this post Link to post Share on other sites