3

got a (I guess...) very simple problem:

I want to set a session within a function. Simple situation:

I got a login form. After subimitting the form, I call a function "login" which checks if user has authenticated. If yes, a session should be set.

Here some very simple code:

session_start();

function login() {
  $SESSION['login'] = true;
}

if (isset($_REQUEST['doLogin'])) {
  login();
  // is session is set here, it works...
}

if ($SESSION['login'] === true) echo 'you are logged in';

But this doesn't work. Why? Thanks alot!

1
  • I like that you caught $_REQUEST but not $SESSION, also its considered bad practice to use $_REQUEST, instead you should use $_POST, $_GET, or $_COOKIE depending on what you are doing... Commented Aug 4, 2010 at 21:59

1 Answer 1

21

You are using $SESSION you need to be using $_SESSION

Sign up to request clarification or add additional context in comments.

2 Comments

Uh damn I'm really embarrassed. Haven't coded php for month and obvisously I've lost my eye for it. thank you and sorry this superfluous "question" ;)
It happens to the best of us :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.