Speedysnail6 Posted October 9, 2013 Share Posted October 9, 2013 (edited) Hi, I'm not sure if either I just have had a stupid error or what. Here is my code on the page with the functions for my script, which is called using require_once() on my other page. session_start(); function log_in($username, $password) { global $ss_con; $_SESSION['logged_in'] = 'true'; $_SESSION['username'] = $username; } This is the code for the other page that has require once... require_once('firstpage.php'); log_in(); if ($_SESSION['logged_in'] != 'true') { echo $_SESSION['logged_in']; echo 'fail!'; } The responce I get is "fail!" Don't worry about log_in() being set. I did that on another page on the same host that just forwards to this. Please help me! Edited October 9, 2013 by Speedysnail6 Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted October 9, 2013 Share Posted October 9, 2013 Try putting session_start at the very top of the page that requires your functions. Also, never, ever, ever use 'global'. For anything. You're already using the function's argument list. Just pass $ss_con in through it like you do with the other arguments. Quote Link to comment Share on other sites More sharing options...
Speedysnail6 Posted October 9, 2013 Author Share Posted October 9, 2013 Try putting session_start at the very top of the page that requires your functions. Also, never, ever, ever use 'global'. For anything. You're already using the function's argument list. Just pass $ss_con in through it like you do with the other arguments. I appreciate your help, but that isn't the problem. In the function page, BELOW the function log_in, I put $_SESSION['logged_in'] = 'true'; $_SESSION['username'] = $username; and it worked. It may be a problem with the log_in() being called, but I doubt it. Are you sure sessions can be set INSIDE a function? Quote Link to comment Share on other sites More sharing options...
Speedysnail6 Posted October 9, 2013 Author Share Posted October 9, 2013 Wait a sec... I think I got it... Thanks for your help! Quote Link to comment Share on other sites More sharing options...
Speedysnail6 Posted October 9, 2013 Author Share Posted October 9, 2013 Sorry about last comment... I still need help! Quote Link to comment Share on other sites More sharing options...
.josh Posted October 9, 2013 Share Posted October 9, 2013 well there's nothing wrong with the code you presented. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.