|
|
|
|
![]() ![]() |
Mar 13 2007, 10:18 PM
Post
#1
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 31 Joined: 9-August 06 Member No.: 28,049 |
While dealing with such a links in php
CODE page.php?id=1 i dont want that someone access this page directly using page.php.. i can give some custom message incase someone try to access page like: CODE page.php okay i can make it by using if condition etc..but the other problem is that, if someone try to access like, CODE 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 |
|
|
|
Mar 13 2007, 10:37 PM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 412 Joined: 4-October 06 From: Psychedelic Realms Member No.: 31,079 |
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
|
|
|
|
Mar 13 2007, 10:57 PM
Post
#3
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,882 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
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. CODE $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. CODE $submit = $_GET[page]; echo $_GET[page]; // echo to confirm the value as a test only if( !isset($_GET[page]) ) { // 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. |
|
|
|
Apr 13 2007, 10:07 PM
Post
#4
|
|
|
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 975 Joined: 25-September 05 From: The dungeon deep below the foundation of trap17 Member No.: 12,251 |
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. |
|
|
|
Nov 28 2007, 08:02 PM
Post
#5
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 102 Joined: 25-November 07 Member No.: 53,695 |
this is the correct code
CODE <?php $variable = $_GET['id']; switch($variable) { default: include('home.php'); break; case "forum": include('forum.php'); break; } ?> instructions: CODE case "forum": include([u]'forum.php'[/u]); break; = change - forum.php to the urlforum - change to your id (underlined) which will come in CODE index.php?id=[u]forum[/u] CODE $variable = $_GET['id']; -change id to what you want here (underlined) index.php?id=123
This post has been edited by mahirharoon: Dec 2 2007, 03:23 PM |
|
|
|
Nov 30 2007, 09:47 AM
Post
#6
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 102 Joined: 13-October 07 Member No.: 51,530 |
what happens if case isn't forum? if it si something else. will it for sure go to default value, or ?
thanks |
|
|
|
Nov 30 2007, 11:57 AM
Post
#7
|
|
|
apt-get moo ![]() Group: [MODERATOR] Posts: 2,055 Joined: 28-May 05 From: Hertfordshire, England Member No.: 7,593 ![]() |
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. |
|
|
|
Dec 21 2007, 05:36 PM
Post
#8
|
|
|
Newbie ![]() Group: Members Posts: 4 Joined: 20-December 07 Member No.: 55,063 |
CODE <?php> if {get=[id=1] }else{ header location = page.php ?> something like that ....(sorry for my php scripting...i had a bit of hurry) |
|
|
|
![]() ![]() |
Similar Topics