问题
I have a flash app which captures image thorugh webcam and stores it in a file throught save.php (below). Now the problem I have is that I am unable to access my session variables when save.php is loaded. Is there a different method I need to use when calling session variables?
<?php
include 'session.php';
sec_session_start();
$userid=$_SESSION['user_id'];
$w = 300;
$h = 400;
$img = imagecreatetruecolor($w, $h);
imagefill($img, 0, 0, 0xFFFFFF);
$rows = 0;
$cols = 0;
for($rows = 0; $rows < $h; $rows++){
$c_row = explode(",", $_POST['px' . $rows]);
for($cols = 0; $cols < $w; $cols++){
$value = $c_row[$cols];
if($value != ""){
$hex = $value;
while(strlen($hex) < 6){
$hex = "0" . $hex;
}
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
$test = imagecolorallocate($img, $r, $g, $b);
imagesetpixel($img, $cols, $rows, $test);
}
}
}
if(isset($userid)){
$fp = fopen("name.jpg", "w");
ob_start();
imagejpeg($img, "", 90);
$img = ob_get_contents();
ob_end_clean();
fwrite($fp, $img);
echo "name.jpg";
echo $userid;
exit;
}
?>
This session.php
function sec_session_start() {
$session_name = 'sec_session_id';
$secure = true;
$httponly = true;
ini_set('session.use_only_cookies', 1);
$cookieParams = session_get_cookie_params();
$cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"],
$secure, $httponly);
session_name($session_name);
session_start(); // Start the php session
session_regenerate_id(true);
}
data is sent from flash to save.php through
load_var.sendAndLoad("save.php", result_lv, "POST");
thank you for you time.
UPDATE
Ok now I am trying to pass the session variable to flash and retrieve it in save.php. This is how flsahvars are used.
var flashvars = {
phpsessionid:<?php print $user_id;?>,
};
var cam = new SWFObject("webcamvid.swf", "player_mc", "400", "500", "8",
"#336699",flashvars);
cam.addParam("quality", "high");
cam.addParam("wmode", "transparent");
cam.addParam("pluginurl", "http://www.macromedia.com/go/getflashplayer");
cam.addParam("pluginspage", "http://www.macromedia.com/go/getflashplayer");
<!--so.addParam("allowFullScreen", "true"); -->
cam.addParam("salign", "t");
cam.write("takepic");
This is used to retrieve flashvars in flash app:
function getFlashVars():Object {
return Object( LoaderInfo( this.loaderInfo ).parameters );
}
var _var1=getFlashVars().phpsessionid;
And then send.
_var1.sendAndLoad("save.php", PHPSESSNID, "POST");
Please note the flash also has
load_var.sendAndLoad("save.php", result_lv, "POST");
which is another variable.
I am unable to retrieve the _var1 in save.php. Any idea how I can make this work Thanks
回答1:
Add session_start(); in the topmost part of your PHP code first !
<?php
session_start();
/*
your code
*/
?>
回答2:
ok so in this all you need to do is use session as following.
function sec_session_start() {
$session_name = 'sec_session_id';
$secure = **flase;**
$httponly = true;
ini_set('session.use_only_cookies', 1);
$cookieParams = session_get_cookie_params();
$cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"],
$secure, $httponly);
session_name($session_name);
session_start(); // Start the php session
session_regenerate_id(true);
}
call the session start function at very start of your file. double, triple and Quadruple check the code or any slightest error and you should be able to access your session variable.
来源:https://stackoverflow.com/questions/16300641/unable-to-call-access-session-variable