$_GET

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
new_developer
Forum Newbie
Posts: 4
Joined: Sat Mar 11, 2006 7:01 am

$_GET

Post by new_developer »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi,

I am brand new to coding in PHP and new to this forum and I need help. I am working on an existing website. Everything goes throug an index.php file and there are many include files. The files are 'called' with an action as in a=[i]action_name[/i].

The following code is in the index.php file:

Code: Select all

if (isset($_GET) && ($_GET["a"] != "")) {

	$nextLoc = $_GET["a"];
	
} else if (isset($a) && ($a != "")) {

	$nextLoc = $a;

} else {
	
	// Default Location.
	$nextLoc = "Main";

}
Further down in the code the $nextloc is being concatenated to the include file name. I understand what is being done here but what I don't understand is where the action variable is being associated with a file name. I am somewhat lost. Is this enough info for someone to help me out?

For example, the action variable 'profile' calls a file called ttse_erv_profileform.inc. And 'profile_entry' calls ttse_erv_profileentry.inc and so on.

Any insight is greatly appreciated.

I should add that this is PHP 4.33, an Oracle 10g database, on a RedHat Linux 3.0AS, and an Apache 1.3.28 web server.

Thanks,
new_developer


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

The code you are looking at uses $_GET variables to let the user access different pages of the website, which are seperated from the main code and shown in the webpage using include(). $_GET variables are defined by the URL, index.php?dog=poodle would define $_GET['dog'] as 'poodle' in your code.

eg.
mydomain.com/index.php?a=profile would show you the include file defined for 'profile', which is the profile page.
mydomain.com/index.php?a=something would show you the include file deined for 'something', if 'something' is not a valid page, I would imagine it would just show you the home page.

It's an easy way to allow basic templating in your website.

An example of how I would use this method is:

Code: Select all

<?php

echo 'HTML header';

if(isset($_GET['a'])) {
  if(!include('includes/' . $_GET['a'])) echo 'That page doesn\'t exist';
} else {
  echo 'No page specified.';
}

echo 'HTML footer';

?>
I presume the code you have is using a switch case statement to decipher which file is included depending on what page name is passed to the page, my example would require the page name to actually be the script name.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

what about.. index.php?page=../ :-D
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
new_developer
Forum Newbie
Posts: 4
Joined: Sat Mar 11, 2006 7:01 am

Post by new_developer »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


[quote]eg. 
mydomain.com/index.php?a=profile would show you the include file defined for 'profile', which is the profile page. 
mydomain.com/index.php?a=something would show you the include file deined for 'something', if 'something' is not a valid page, I would imagine it would just show you the home page. 
[/quote]

Thank you for the reply. That part I completely understand. What I don't understand where he is setting the variable. All include files have the same file naming convention. Let's say it is aaaa_bbbb_something.inc.

For example, if I type in http://www.websitename.com/index.php?a=profile I get a new page and that page uses the .inc file aaaa_bbbb_profilemain.inc. If I add a=profile_entry it calls the .inc file aaaa_bbbb_profileform.inc and so on. He determines what the action is (a=???) and based on that action sets the variable $nextloc. He then concatenates $nextloc with the filename as follows:

Code: Select all

if ( ($nextLoc != "LoginAction") && ($nextLoc != "timeout") ) {
   if ($_COOKIE["Passport"])  {

      include($incDir."aaaa_bbbb_AuthenticateCookie.inc");
		
         if ( ($_SESSION["user"] == "") && ($nextLoc != "LoginAction") )   {
		
	if ($loginPrompt) {
				
	// but for now:
	$nextLoc = "Login";
				
				
	} 
        else {
			
	$nextLoc = "LoginFailed";
			
			}
			
		}	
	
	} 
else {
	
		// insert forward to login screen
			// header("Location:  url");
			
		// but for now:
	
		$nextLoc = "Login";
		
	}
}

// include page contents or action
include_once($incDir."aaaa_bbbb_".$nextLoc.".inc");
Here's the part I am missing. Where does he set that the action 'profile' = $nextloc profilemain and that the action 'profile_entry' = $nextloc 'profileform', and so on. Does that make sense? Maybe I am not asking the right question. As far as I understand this somewhere there are global variables being set that associate an action with a file name and i don't know where this is happening.

Thanks,
new_developer


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply