Hallo Ortwin
Danke für deine Einführung in die Contenido Session.
Leider klappt es bei mir nicht.
Wenn ich
$sess = cRegistry::getSession(); in einem Externen File aufrufe (captcha.php) wird es irgend wie $sess nicht gesetzt.
Ich erhalte dan folgende Fehlermeldung:
Code: Alles auswählen
PHP Fatal error: Uncaught Error: Call to a member function isRegistered()
Das File sieht wie folgt aus und liegt in Mandanten Ordner:
Code: Alles auswählen
<?php
// we need to set constant
if (!defined("CON_FRAMEWORK")) {
define("CON_FRAMEWORK", true);
}
global $contenido_path, $contenido, $client, $load_client, $file;
// Set path to current frontend
$frontend_path = str_replace('\\', '/', realpath(dirname(__FILE__) . '/')) . '/';
// include security class and check request variables
//include_once ($contenido_path . 'classes/class.security.php');
//Contenido_Security::checkRequests();
/*
* Do not edit this value!
*
* If you want to set a different enviroment value please define it in your .htaccess file
* or in the server configuration.
*
* SetEnv CON_ENVIRONMENT development
*/
if (!defined('CON_ENVIRONMENT')) {
if (getenv('CONTENIDO_ENVIRONMENT')) {
$sEnvironment = getenv('CONTENIDO_ENVIRONMENT');
} elseif (getenv('CON_ENVIRONMENT')) {
$sEnvironment = getenv('CON_ENVIRONMENT');
} else {
// @TODO: provide a possibility to set the environment value via file
$sEnvironment = 'production';
}
define('CON_ENVIRONMENT', $sEnvironment);
}
// Include the config file of the frontend to initialize client and language id
include_once($frontend_path . 'data/config/' . CON_ENVIRONMENT . '/config.php');
// Clients local configuration
if (file_exists($frontend_path . 'data/config/' . CON_ENVIRONMENT . '/config.local.php')) {
@include($frontend_path . 'data/config/' . CON_ENVIRONMENT . '/config.local.php');
}
// CONTENIDO startup process
if (!is_file($contenido_path . 'includes/startup.php')) {
die("<h1>Fatal Error</h1><br>Couldn't include CONTENIDO startup.");
}
include_once($contenido_path . 'includes/startup.php');
// start session etc., see phplib for more info
//page_open(array ('sess' => 'Contenido_Frontend_Session', 'auth' => 'Contenido_Frontend_Challenge_Crypt_Auth', 'perm' => 'Contenido_Perm'));
function randomString($len) {
function make_seed(){
list($usec , $sec) = explode (' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
//Der String $possible enthält alle Zeichen, die verwendet werden sollen
$possible="ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789";
$str="";
while(strlen($str)<$len) {
$str.=substr($possible,(rand()%(strlen($possible))),1);
}
return($str);
}
$sess = cRegistry::getSession();
$captchaspam = randomString(5); //Die Zahl bestimmt die Anzahl stellen
If (!$sess->isRegistered('captchaspam')) {
$sess->register("captchaspam");
}
// phplib cleanup
//page_close();
$strPath = dirname(__FILE__).'/captcha';
header('Content-type: image/png');
$img = ImageCreateFromPNG($strPath.'/captcha.PNG'); //Backgroundimage
$color = ImageColorAllocate($img, 125, 125, 125); //Farbe
$ttf = $strPath."/Anorexia.ttf"; //Schriftart
$ttfsize = 26; //Schriftgrösse
$angle = rand(0,5);
$t_x = rand(5,10);
$t_y = 35;
imagettftext($img, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $captchaspam);
imagepng($img);
imagedestroy($img);
?>
LG - derju