Credit Counseling - Gas Suppliers - Home Insurance - Share Prices - Credit Card Debt Consolidation

PDA

View Full Version : Multiple pages in one file


kc3
Mar 7th 2006, 6:56 pm
There is a php file that has the pages selected using a simple if function like this
if ( $mode == "register" ) {
// The content here
exit;
};
But if you go to the following URL it does not the the contents of that if statement and just skips it.
http://www.somedomain.com/dir/file.php?mode=register
I realy have to know why this is happening.

clancey
Mar 7th 2006, 9:21 pm
The material after the question mark in the URL is called the query strong. You access it as follows:

$mode = strtolower( $_SERVER["QUERY_STRING"] );

In you case, it is going to return "mode=register"

So your test becomes:

if($mode == "mode=register")

unless you split the query to find out what type it is and what it is. Your type becomes "mode" and what your are seeking is the "register" mode.

LGRComp
Mar 7th 2006, 10:16 pm
Register globals is turned off on the server, as it should be. You have to access mode like so in your code:



$mode=$_GET['mode'] ;
if ( $mode== "register" ) {
// The content here
exit;
};


Of course you might want to do some checks about what is allowed in modes.

kc3
Mar 7th 2006, 10:18 pm
Oh okay, why thank you. :)

clancey
Mar 8th 2006, 12:58 pm
$mode=$_GET['mode'] ;
My oversight. There is always more than one way to skin a cat in PHP and perl.

kc3
Mar 8th 2006, 9:01 pm
Hm... How come when I put the $_GET in my file none of my tables are listing the users from my database anymore. It uses normal pagination and works fine without it. Also, why are the link on this page not working with IE it only works with Firefox :( Last time I checked IE was capable of showing links. wtf?

clancey
Mar 8th 2006, 9:57 pm
Putting the line $mode = $_GET['mode']; in your file is not going to affect your ability to list users in the database; nor affect a browsers ability to render the page.

When this happens, it suggests that you have a critical error in the file. Error reports should show up in your web broswer file. I also find it helpful to run pages I have just edited from the command line to see if they are generating errors.

If the links are not showing, take a look at the source for the rendered page and make sure they are valid. This is just part of the normal write-run-debug cycle of program development. Programming takes patience and a good eye.

kc3
Mar 8th 2006, 10:15 pm
omg, lol, there was a mistake in one of the $_GET variables. That's why I was confused clancey, thanks for all your help :)

clancey
Mar 9th 2006, 3:00 pm
You are most welcome. I am glad I could help.