dongyanghan0556 2011-06-16 08:43
浏览 57

用php问题创建图像

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 )

  • 写回答

2条回答 默认 最新

  • doujingqu3030 2011-06-16 09:04
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据