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
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Mon May 28, 2007 9:39 am
franknu wrote: the problem is that i should also display the password and it is only displaying the user
That's because the only thing that you are saving is the user.
franknu wrote: Code: Select all
$_SESSION = array('User_Name'=>$_POST['User_Name']);
If you want both, save both into the array. I, personally, wouldn't recommend saving the password, as you should only need to check once, but it's up to you.
And it IS carrying the user name to the next page. It's in the $_SESSION array.
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon May 28, 2007 10:14 am
Ok On Page1
with <pre>_SESSION:<?php print_r($_SESSION); ?></pre>
i am displaying this
SESSION:Array
(
[User_Name] => franklin
[Password] => franklin01
)
and here is my code
Code: Select all
<?
if ( isset($_POST['User_Name']) && isset ( $_POST['Password']) ) {
session_start();
session_regenerate_id();
$_SESSION = array('User_Name'=>$_POST['User_Name'] ,
'Password'=>$_POST['Password']);
}
?>
however on page2
i am displaying
SESSION:Array
(
[User_Name] =>
[Password] =>
)
with <pre>_SESSION:<?php print_r($_SESSION); ?></pre>
and this is the code for page2
Code: Select all
<?php
session_start();
if (isset($_SESSION['User_Name']) && isset($_SESSION['Password'])) {
session_regenerate_id();
$_SESSION = array('User_Name'=>$_POST['User_Name'] ,
'Password'=>$_POST['Password']);
}
?>
<html>
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Mon May 28, 2007 10:29 am
... Odd. Where are you testing from?
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon May 28, 2007 10:32 am
i dont get ur answer but when i take the Session to the next page it is not displaying the values
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Mon May 28, 2007 10:40 am
Lol, I understood you the first time.
Are you testing locally or remotely?
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Mon May 28, 2007 11:04 am
Remote, everything is on the server already
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon May 28, 2007 11:27 am
franknu wrote: and this is the code for page2
Code: Select all
<?php
session_start();
if (isset($_SESSION['User_Name']) && isset($_SESSION['Password'])) {
session_regenerate_id();
$_SESSION = array('User_Name'=>$_POST['User_Name'] ,
'Password'=>$_POST['Password']);
}
?>Why do you assign the array
again on page 2? Are User_Name and Password POSTed again?
No they are not. Script #1 sets the session data, script #2 uses them.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Mon May 28, 2007 12:45 pm
volka wrote: franknu wrote: and this is the code for page2
Code: Select all
<?php
session_start();
if (isset($_SESSION['User_Name']) && isset($_SESSION['Password'])) {
session_regenerate_id();
$_SESSION = array('User_Name'=>$_POST['User_Name'] ,
'Password'=>$_POST['Password']);
}
?>Why do you assign the array
again on page 2? Are User_Name and Password POSTed again?
No they are not. Script #1 sets the session data, script #2 uses them.
Wow.. It's as though I stopped reading at session_regenerate_id(); (.. which I did :-p).