PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
You should use the "session_start()" at the begining of the .php file and not inside a class method. Unless I am mistaken the "session_start()" should be the first line of code on the page. If you want to assign values to the $_SESSION["VARNAME"] you can do that after the session has been created. The example below is what I am using on my pages:
<?php
class Sessions {
public function createSession($userInformation){
if(is_resource($userInformation)){
$user = @mysql_fetch_array($userInformation, MYSQL_ASSOC);
$_SESSION["USERNAME"] = $user["username"];
//remainder code here...
}else{
header("Location: http://www.whateverPage.php");
}
}
}
?>
I use a method simiar to the one above at the end of the authentication page in order to establish the session and assign their values. After that I only call the "session_start()" at the begining of each page and that does it for me.