无法调用访问会话变量 [英] Unable to call access session variable
问题描述
我有一个Flash应用程序捕捉图像thorugh网络摄像头并将其存储在一个文件中throught save.php(下图)。现在,我的问题是,我不能当save.php加载访问我的会话变量。是否有不同的方法,我需要调用会话变量时使用?
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;
}
?>
这session.php文件
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);
}
数据从闪存发送到save.php通过
data is sent from flash to save.php through
load_var.sendAndLoad("save.php", result_lv, "POST");
感谢您为您的时间。
更新
好了,现在我想通过会话变量闪烁,在save.php检索。这是如何flsahvars被使用。
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");
这是用来检索的Flash应用程序Flash变量:
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");
请注意,闪光灯还具备
load_var.sendAndLoad("save.php", result_lv, "POST");
这是另一种可变的。
which is another variable.
我无法检索save.php的_var1。任何想法如何,我可以使这项工作谢谢
I am unable to retrieve the _var1 in save.php. Any idea how I can make this work Thanks
推荐答案
确定这样所有这一切,你需要做的是利用会话如下。
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);
}
致电十分会话启动功能,启动文件。双人间,三人间和四人间检查code或任何丝毫的错误,你应该能够访问您的会话变量。
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.
这篇关于无法调用访问会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!