Jump to content

Recommended Posts

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 by Speedysnail6
Link to comment
https://forums.phpfreaks.com/topic/282851-session-inside-a-function/
Share on other sites

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.