Posted by Erlend Klakegg Bergheim on 02/01/06 01:25
Stefan Mueller skrev:
> I'd like to write a user login where a user can enter his username and
> password. If it's correct he/she should be able to access all my PHP pages.
> My plan was to set a session variable like e.g. $_SESSION['auth_ok'] to TRUE
> (user login was okay) resp. FALSE (user login was wrong) and to test at the
> beginning of each PHP page is this variable is TRUE. However, in my example
> below I'm not even able to use the session variable
> $_SESSION['session_application'] of login.php in the second PHP file
> logincheck.php. $_SESSION['session_application'] is always empty.
>
>
> login.php
> =========
> <html>
> <body>
> <?php
> session_start();
> $_SESSION['session_application'] = "My Test Application";
> ?>
> ...
> <form name = "my_form" action = "logincheck.php" method = "post"
> accept-charset = "iso-8859-1">
> ...
> <?php
> echo $_SESSION['session_application'];
> ?>
> ...
> <input type = "text" name = "username" value = "">
> <input type = "password" name = "password" value = "">
> <input type = "submit" name = "my_button" value = "Login">
> ...
> </form>
> </body>
> </html>
>
> logincheck.php
> ==============
> <html>
> <body>
> <?php
> echo $_SESSION['session_application'];
> echo "Username: " . $_POST['username'] . "<br>";
> echo "Password: " . $_POST['password'] . "<br>";
> ?>
> </body>
> </html>
>
>
> Why is $_SESSION['session_application'] in logincheck.php empty? What did I
> do wrong?
>
> Is my approach to do what I'd like to do with a session variable like e.g.
> $_SESSION['auth_ok'] correct?
> Stefan
You must _allways_ use session_start() before using $_SESSION, also when
you just wanna show the information i $_SESSION.
<URL: http://www.php.net/session >
--
Vennlig hilsen
Erlend Klakegg Bergheim
[Back to original message]
|