Checking if a session is active
- by Josh
I am building a captcha class. I need to store the generated code in a PHP session. This is my code so far:
<?php
class captcha
{
private $rndStr;
private $length;
function generateCode($length = 5)
{
$this->length = $length;
$this->rndStr = md5(time() . rand(1, 1000));
$this->rndStr = substr($rndStr, 0, $this->length);
return $rndStr;
if(session_id() != '')
{
return "session active";
} else {
return "no session active";
}
}
}
?>
And using this code to check:
<?php
include('captcha.class.php');
session_start();
$obj = new captcha();
echo $obj->generateCode();
?>
But it doesn't output anything to the page, not even a PHP error. Does someone know why this is? And is there a better way I can check if I've started a session using session_start()?
Thanks.