PHP自定义会话+变量$ _SESSION不起作用

时间:2015-08-25 11:46:21

标签: php session

我正在搜索有关如何为我的项目创建海关会话的一些教程。我有一个验证码系统,它将验证码存储在$ _SESSION ['CAPTCHA_CODE']中。如果我使用简单的“session_start();”,一切正常,但如果我改变我的功能,它会停止存储我的验证码。我已经试着知道它为什么不起作用,但我找不到错误。在这种情况下,有人可以帮助我吗?感谢。

我的SessionCode:

function sec_session_start() {
    $session_name = 'FL_SEC_SESSION';   // Set a custom session name
    $secure = SECURE;
    // This stops JavaScript being able to access the session id.
    $httponly = true;
    // Forces sessions to only use cookies.
    if (ini_set('session.use_only_cookies', 1) === FALSE) {
        header("Location: ./errno.php");
        exit();
    }
    // Gets current cookies params.
    $cookieParams = session_get_cookie_params();
    session_set_cookie_params($cookieParams["lifetime"],
        $cookieParams["path"], 
        $cookieParams["domain"], 
        $secure,
        $httponly);
    // Sets the session name to the one set above.
    session_name($session_name);
    session_start();            // Start the PHP session 
    session_regenerate_id(true);    // regenerated the session, delete the old one. 
}

我的验证码:

include('base_func.php');
sec_session_start();
$random_alpha = md5(rand());
$captcha_code = substr($random_alpha, 0, 6);
$_SESSION['CAPTCHA_CODE'] = $captcha_code;
$im = @imagecreatetruecolor(70,30);
# important part one
imagesavealpha($im, true);
imagealphablending($im, false);
# important part two
$white = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefill($im, 0, 0, $white);
# do whatever you want with transparent image
$lime = imagecolorallocate($im, 204, 255, 51);
$captcha_text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 5, 5, $captcha_code, $captcha_text_color);
// imagettftext($im, $font, 0, 0, $font - 3, $lime, "captcha.ttf", $string);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);

最后我得到所有信息的标题:

require('inc/config.php');
include('inc/idioma.php');
sec_session_start();
//sec_session_start();
initPageLoader();

// Caso manutenção esteja a decorrer, encaminhar para página de manutenção
if(getmaintenance($link) == "1"){
header("Location: mip.php");
}

// Proper Parse URL
$query = proper_parse_str($_SERVER['QUERY_STRING']);

// desativar depois de estar tudo concluido
ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(E_ALL);
// desativar depois de estar tudo concluido

请注意在标题中我不包括base_func.php(我的会话的功能在哪里,但只有具有base_func.php链接的配置。

如果有人可以帮助我,我很高兴:)

0 个答案:

没有答案