I have a script picture.php that contains this code
<?php
if(isset($_GET['pic']) && isset($_SESSION))
{
$img = imageCreateFromPng($_GET['pic']);
header("Content-type: image/png");
imagePng($img);
imagedestroy($img);
}
else
{
echo 'hidden';
die;
}
?>
I'm trying to hide the image generated from picture.php when session is not started. I have other page named show.php which contains a code
<?php
session_start();
echo '<img src="picture.php?pic=apple.png" />' ;
?>
The problem is the image won't show in show.php even the session is started in show.php why?
If you are going to check some session variable then dont forget to start session on top
Try:
<?php
session_start();
if(empty($_GET['pic']) && empty($_SESSION))
{
echo 'hidden';
die;
}
else
{
$img = imageCreateFromPng($_GET['pic']);
header("Content-type: image/png");
imagePng($img);
imagedestroy($img);
}
?>
may this help... start_session();
You actually might want to "flag" if the session is considered started.
picture.php:
session_start();
if(isset($_GET['pic']) && isset($_SESSION['initialized']))
{
unset($_SESSION['initialized']);
$img = imageCreateFromPng($_GET['pic']);
header("Content-type: image/png");
imagePng($img);
imagedestroy($img);
}
else
{
echo 'hidden';
die;
}
show.php:
session_start();
$_SESSION['initialized'] = true;
echo '<img src="picture.php?pic=apple.png" />' ;