用php创建图像问题
我的index.php文件有类似的东西:
<?php
session_start();
$_SESSION[some_value] = 1;
?>
<img src="image.php" alt="some image"/>
<?php
$_SESSION[some_value] = 0;
?>
我的image.php文件看起来像(基本代码):
<?php
session_start();
header("Content-Type: image/png");
$im = @imagecreate(400, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,"session value is : {$_SESSION[some_value]}", $text_color);
imagepng($im);
imagedestroy($im);
?>
现在,当我在浏览器中加载index.php页面时,图像中的值是会话值是:0< /code>,如何让它显示1,然后在
index.php
中编写代码将其设置为0(在image.php
代码中添加将值设置为0是不是我要找的)
my index.php file i have somethingk like :
<?php
session_start();
$_SESSION[some_value] = 1;
?>
<img src="image.php" alt="some image"/>
<?php
$_SESSION[some_value] = 0;
?>
my image.php file i have look like ( basic code ) :
<?php
session_start();
header("Content-Type: image/png");
$im = @imagecreate(400, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,"session value is : {$_SESSION[some_value]}", $text_color);
imagepng($im);
imagedestroy($im);
?>
Now, when i load my index.php page in browser the value in image is session value is : 0
, how to make it to show 1 and then code in index.php
to set it to 0 ( adding in image.php
code to set value to 0 is not what i'm looking for )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您会遇到问题,因为在您的代码中,即使两个脚本都使用
$_SESSION
数组,它们也不共享会话内存。这是 PHP 存储
$_SESSION
数组值的方式和时间的本质。相反,您需要一个共享存储(例如数据库或共享内存)来在脚本之间交换值。
You run into problems because in your code both scripts do not share the memory of the session even if both are using the
$_SESSION
array.That's by the nature of how and when PHP stores the values of the
$_SESSION
array.Instead you need a shared store like a database or shared memory to exchange values between your scripts.
问题是浏览器在加载 index.php 后加载 image.php 。
你可以这样做:
但这取决于你的特定目的。
The problem is that the browser loads image.php after index.php is loaded.
You can do something like this:
But it depends on your particular purpose.