Search the Community
Showing results for tags 'include_once session global'.
-
Hello everyone! I need help with a problem I'm trying to solve for 2 days now. I know there must be a way and I hope you guys can help me out. What I have here is this. In my website the user is logging in, and I check in the mysql database if the user and password matches. If yes I want to save in php variables all my values from the database such as username, firstname, lastname to use it later on. I can do this but the problem is everytime I go to the page where I use those variables, those are reinitialized and I get the error: Notice: Undefined index: user_id I will write a short example of code with what I try to do: //A.php<?phprequire 'core.inc.php'; // core.inc.php contains the connection to the db and the session_start() login_form(); function login_form(){ $username = $_POST['username']; $password = $_POST['password']; // if username and password are set I do a query on the db and check if it matches // if it matches $_SESSION['user_id'] = $user_id; } ?>--------------------------------------------------------------------------// B.php<?php include 'A.php'; echo $_SESSION['user_id']; ?>Now this works perfectly fine first time I go to B.php the output is 1 or 2 or whatever the session is. But if I go to another page and then go to B.php again the include function is called again so A.php isloaded again, A.php will call core.inc.php so the session is restarted and my variables are set to 0which I don't want. I've tried a lot of things, include_once, include only the variables, global variables, check if the session is started. Nothing worked...Do you lads have a suggestion for me? I would really appreciate it!