コード例 #1
0
ファイル: functions.php プロジェクト: hungnv0789/vhtm
/**
* Sets a cookie based on vBulletin environmental settings
*
* @param	string	Cookie name
* @param	mixed	Value to store in the cookie
* @param	boolean	If true, do not set an expiry date for the cookie
* @param	boolean	Allow secure cookies (SSL)
* @param	boolean	Set 'httponly' for cookies in supported browsers
*/
function vbsetcookie($name, $value = '', $permanent = true, $allowsecure = true, $httponly = false)
{
	if (defined('NOCOOKIES'))
	{
		return;
	}

	global $vbulletin;

	if ($permanent)
	{
		$expire = TIMENOW + 60 * 60 * 24 * 365;
	}
	else
	{
		$expire = 0;
	}

	// IE for Mac doesn't support httponly
	$httponly = (($httponly AND (is_browser('ie') AND is_browser('mac'))) ? false : $httponly);

	// check for SSL
	$secure = ((REQ_PROTOCOL === 'https' AND $allowsecure) ? true : false);

	$name = COOKIE_PREFIX . $name;

	$filename = 'N/A';
	$linenum = 0;

	if (!headers_sent($filename, $linenum))
	{ // consider showing an error message if they're not sent using above variables?

		if ($value === '' OR $value === false)
		{
			// this will attempt to unset the cookie at each directory up the path.
			// ie, path to file = /test/vb3/. These will be unset: /, /test, /test/, /test/vb3, /test/vb3/
			// This should hopefully prevent cookie conflicts when the cookie path is changed.

			if ($_SERVER['PATH_INFO'] OR $_ENV['PATH_INFO'])
			{
				$scriptpath = $_SERVER['PATH_INFO'] ? $_SERVER['PATH_INFO'] : $_ENV['PATH_INFO'];
			}
			else if ($_SERVER['REDIRECT_URL'] OR $_ENV['REDIRECT_URL'])
			{
				$scriptpath = $_SERVER['REDIRECT_URL'] ? $_SERVER['REDIRECT_URL'] : $_ENV['REDIRECT_URL'];
			}
			else
			{
				$scriptpath = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF'];
			}

			$scriptpath = preg_replace(
				array(
					'#/[^/]+\.php$#i',
					'#/(' . preg_quote($vbulletin->config['Misc']['admincpdir'], '#') . '|' . preg_quote($vbulletin->config['Misc']['modcpdir'], '#') . ')(/|$)#i'
				),
				'',
				$scriptpath
			);

			$dirarray = explode('/', preg_replace('#/+$#', '', $scriptpath));

			$alldirs = '';
			$havepath = false;
			if (!defined('SKIP_AGGRESSIVE_LOGOUT'))
			{
				// sending this many headers has caused problems with a few
				// servers, especially with IIS. Defining SKIP_AGGRESSIVE_LOGOUT
				// reduces the number of cookie headers returned.
				foreach ($dirarray AS $thisdir)
				{
					$alldirs .= "$thisdir";

					if ($alldirs == $vbulletin->options['cookiepath'] OR "$alldirs/" == $vbulletin->options['cookiepath'])
					{
						$havepath = true;
					}

					if (!empty($thisdir))
					{
						// try unsetting without the / at the end
						exec_vbsetcookie($name, $value, $expire, $alldirs, $vbulletin->options['cookiedomain'], $secure, $httponly);
					}

					$alldirs .= "/";
					exec_vbsetcookie($name, $value, $expire, $alldirs, $vbulletin->options['cookiedomain'], $secure, $httponly);
				}
			}

			if ($havepath == false)
			{
				exec_vbsetcookie($name, $value, $expire, $vbulletin->options['cookiepath'], $vbulletin->options['cookiedomain'], $secure, $httponly);
			}
		}
		else
		{
			exec_vbsetcookie($name, $value, $expire, $vbulletin->options['cookiepath'], $vbulletin->options['cookiedomain'], $secure, $httponly);
		}
	}
	else if (empty($vbulletin->db->explain))
	{ //show some sort of error message
		global $templateassoc, $vbulletin;
		if (empty($templateassoc))
		{
			// this is being called before templates have been cached, so just get the default one
			$template = $vbulletin->db->query_first_slave("
				SELECT templateid
				FROM " . TABLE_PREFIX . "template
				WHERE title = 'STANDARD_ERROR' AND styleid = -1
			");
			$templateassoc = array('STANDARD_ERROR' => $template['templateid']);
		}
		eval(standard_error(fetch_error('cant_set_cookies', $filename, $linenum)));
	}
}
コード例 #2
0
ファイル: functions.php プロジェクト: 0hyeah/yurivn
/**
* Sets a cookie based on vBulletin environmental settings
*
* @param	string	Cookie name
* @param	mixed	Value to store in the cookie
* @param	boolean	If true, do not set an expiry date for the cookie
* @param	boolean	Allow secure cookies (SSL)
* @param	boolean	Set 'httponly' for cookies in supported browsers
*/
function vbsetcookie($name, $value = '', $permanent = true, $allowsecure = true, $httponly = false)
{
    if (defined('NOCOOKIES')) {
        return;
    }
    global $vbulletin;
    if ($permanent) {
        $expire = TIMENOW + 60 * 60 * 24 * 365;
    } else {
        $expire = 0;
    }
    // IE for Mac doesn't support httponly
    $httponly = ($httponly and (is_browser('ie') and is_browser('mac'))) ? false : $httponly;
    // check for SSL
    $secure = (REQ_PROTOCOL === 'https' and $allowsecure) ? true : false;
    $name = COOKIE_PREFIX . $name;
    $filename = 'N/A';
    $linenum = 0;
    if (!headers_sent($filename, $linenum)) {
        // consider showing an error message if they're not sent using above variables?
        if ($value === '' or $value === false) {
            // this will attempt to unset the cookie at each directory up the path.
            // ie, path to file = /test/vb3/. These will be unset: /, /test, /test/, /test/vb3, /test/vb3/
            // This should hopefully prevent cookie conflicts when the cookie path is changed.
            if ($_SERVER['PATH_INFO'] or $_ENV['PATH_INFO']) {
                $scriptpath = $_SERVER['PATH_INFO'] ? $_SERVER['PATH_INFO'] : $_ENV['PATH_INFO'];
            } else {
                if ($_SERVER['REDIRECT_URL'] or $_ENV['REDIRECT_URL']) {
                    $scriptpath = $_SERVER['REDIRECT_URL'] ? $_SERVER['REDIRECT_URL'] : $_ENV['REDIRECT_URL'];
                } else {
                    $scriptpath = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF'];
                }
            }
            $scriptpath = preg_replace(array('#/[^/]+\\.php$#i', '#/(' . preg_quote($vbulletin->config['Misc']['admincpdir'], '#') . '|' . preg_quote($vbulletin->config['Misc']['modcpdir'], '#') . ')(/|$)#i'), '', $scriptpath);
            $dirarray = explode('/', preg_replace('#/+$#', '', $scriptpath));
            $alldirs = '';
            $havepath = false;
            if (!defined('SKIP_AGGRESSIVE_LOGOUT')) {
                // sending this many headers has caused problems with a few
                // servers, especially with IIS. Defining SKIP_AGGRESSIVE_LOGOUT
                // reduces the number of cookie headers returned.
                foreach ($dirarray as $thisdir) {
                    $alldirs .= "{$thisdir}";
                    if ($alldirs == $vbulletin->options['cookiepath'] or "{$alldirs}/" == $vbulletin->options['cookiepath']) {
                        $havepath = true;
                    }
                    if (!empty($thisdir)) {
                        // try unsetting without the / at the end
                        exec_vbsetcookie($name, $value, $expire, $alldirs, $vbulletin->options['cookiedomain'], $secure, $httponly);
                    }
                    $alldirs .= "/";
                    exec_vbsetcookie($name, $value, $expire, $alldirs, $vbulletin->options['cookiedomain'], $secure, $httponly);
                }
            }
            if ($havepath == false) {
                exec_vbsetcookie($name, $value, $expire, $vbulletin->options['cookiepath'], $vbulletin->options['cookiedomain'], $secure, $httponly);
            }
        } else {
            exec_vbsetcookie($name, $value, $expire, $vbulletin->options['cookiepath'], $vbulletin->options['cookiedomain'], $secure, $httponly);
        }
    } else {
        if (empty($vbulletin->db->explain) and !VB_API) {
            // VBIV-12815 Pre-set error message for later
            if (!defined('VB_ERROR_LITE')) {
                define('VB_ERROR_LITE', true);
                define('VB_ERROR_LITE_ERROR', fetch_error('cant_set_cookies', $filename, $linenum));
            } else {
                // If we cannot pre-set, at least display an error.
                echo fetch_error('cant_set_cookies', $filename, $linenum);
                exit;
            }
        }
    }
}