Q:

_SESSION Lost in wordpress

I have this:
captcha.php
<?php
session_start();
$code=rand(1000,9999);
$_SESSION["code"]=$code;
$im = imagecreatetruecolor(50, 24);
$bg = imagecolorallocate($im, 22, 86, 165);
$fg = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
imagestring($im, 5, 5, 5,  $code, $fg);
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

then i call this in other php file:
<img src="captcha.php"/>

but the session is not saved... 
thansk for your help guys!

A:

To start a session using PHP, session_start() needs to be the first thing before any HTML is output:

<?php
session_start();  

from PHP.net:  

Note: To use cookie-based sessions, session_start() must be called
  before outputing anything to the browser.

Since you are including it as an image, this session_start() will not appear early enough in your output.  You need to make sure it's the first thing; I'm not sure how wordpress handles that on its own, perhaps a question for the wordpress forum.  Here is a post I found about the subject.

