faqts : Computers : Programming : Languages : PHP : Common Problems : Sessions and State

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

25 of 34 people (74%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How to pass login and password from first level script to third level script (that means one script is included in another,like that 3 levels)?

Jan 21st, 2008 16:55
Tim Stumbaugh, Matt Gregory, Samatha Kottha, Nathan Wallace,


This is one of the most difficult problems for new users of PHP to 
understand.  PHP is called when the page is called, and then closes 
once the page has been returned to the client.  There are three 
possible ways to handle the problem of passing information between 
script files.
1.) return the variables to the browser as a hidden field in a form.  
You can decide whether or not to encrypt this information before 
plopping it into the HTML.
2.) return the variables in temporary cookies (make sure it is 
temporary.) and then delete the cookies when the user leaves the site.
3.) store the variables, encrypted or not as you prefer, in a database 
table of logged-in users or sessions.
There are other ways of doing this, but they are much harder and in my 
opinion not worth the trouble.
---------------
If you are actually including files (using language construct include,
require, include_once, require_once), the included file inherits the
scope of the line that it was called on. Here's an example:
[main.php]
$some_int=52;
include "inc1.inc.php";
[inc1.inc.php]
echo $some_int; //echoes the number 52