p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Variable question


Message #1 by "kyle ketterer" <bige88fan@a...> on Wed, 3 Apr 2002 22:58:14
Ok I am making a admin login script for my site, to adjust options, 
etc...Basically what it does is, takes info that a user enters in, 
verify's if its the valid admin. But what I need to know is, when the 
script verify's that the admin IS correct, I want the admin and password 
values to be passed on to the actual "adjust option" scripts, I want all 
the other scripts to take the admin info from the login script, and verify 
if its still the correct admin. So how can I pass these values around from 
the login script? Thanks alot,

-kyle. 
Message #2 by "Dan Ostrowski" <dan@t...> on Thu, 4 Apr 2002 01:28:36
actually, this is all covered in the Beginning PHP book by Wrox Press.  
Have you go that?

in short, you get the name and password from a form.  then you check to 
see if it matches the ones in the database.

if they DO, you just register the name and password as "session variables" 
so they stay constant!

usually you put the script that does that in one of your includes, at the 
top of the page.



here is one of my old ones:

---------------------------
session_start();

if (isset($userId) && isset($password)) {
	global $linkId;  // the variable of the database link connection


	$loggedUser = login_check($userId, $password);  
/* login check is a function I made that checks the password and $userId 
against the database.*/

	if(!$loggedUser) {
		$linkId = db_connect();
		session_unset();
		$authFailed = "yes";
	} else {
		session_register("loggedUser");
		session_register("password");
			}
}

----------------------


good luck,
dan
Message #3 by "kyle ketterer" <bige88fan@a...> on Thu, 4 Apr 2002 02:03:49
> actually, this is all covered in the Beginning PHP book by Wrox Press.  
H> ave you go that?

> in short, you get the name and password from a form.  then you check to 
s> ee if it matches the ones in the database.

> if they DO, you just register the name and password as "session 
variables" 
s> o they stay constant!

> usually you put the script that does that in one of your includes, at 
the 
t> op of the page.

> 

> here is one of my old ones:

> ---------------------------
s> ession_start();

> if (isset($userId) && isset($password)) {
	> global $linkId;  // the variable of the database link connection

> 
	> $loggedUser = login_check($userId, $password);  
/> * login check is a function I made that checks the password and $userId 
a> gainst the database.*/

> 	if(!$loggedUser) {
	> 	$linkId = db_connect();
	> 	session_unset();
	> 	$authFailed = "yes";
	> } else {
	> 	session_register("loggedUser");
	> 	session_register("password");
	> 		}
}> 

> ----------------------

> 
g> ood luck,
d> an

Hi dan. Thanks for your help, just one more questions:

Whenever you do a :
session_register("adminname");

does this become a variable. Like would it be $adminname ?

And also, when you click on a hyperlink on that page when the confirmation 
is done, it passes these "session variables" to the next page? Please help 
me! Thanks alot kyle. 

 
Message #4 by "Nikolai Devereaux" <yomama@u...> on Wed, 3 Apr 2002 17:06:56 -0800
> Hi dan. Thanks for your help, just one more questions:
>
> Whenever you do a :
> session_register("adminname");
>
> does this become a variable. Like would it be $adminname ?

Exactly.  You're giving the session handler the name of the variable to
track as a session var.

> And also, when you click on a hyperlink on that page when the
> confirmation is done, it passes these "session variables" to
> the next page?

If you start the session on the other page too, then you should have all the
session variables you registered on the last page, yes.

This can get to be kind of tricky at first, I'd really recommend looking for
a tutorial on sessions.  There's documentation on a lot of sites out there,
start with  php.net or phpbuilder.com or some similar site.


Best o' luck,

Nik

Message #5 by BIGE88FAN@a... on Sat, 6 Apr 2002 14:16:13 EST
--part1_36.25b5acd6.29e0a37d_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Do session vairables only interact with mysql databases? Because I tried it 
without it, and it never seems to work. 

Kyle Ketterer
(bige88fan@a...)

http://nhlrage.com/

Message #6 by "Lawrence" <lkrubner@g...> on Tue, 9 Apr 2002 13:12:40 -0400
From: "kyle ketterer" <bige88fan@a...
> , I want all 
> the other scripts to take the admin info from the login script, and verify 
> if its still the correct admin. So how can I pass these values around from 
> the login script? Thanks alot,

This is why they invented session variables. 



  Return to Index