Reply to Re: Why are my session variables always empty

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация