2013-10-28 80 views
-2

我有一個腳本picture.php包含此代碼PHP:試圖隱藏圖像,如果會議沒有啓動

<?php 
if(isset($_GET['pic']) && isset($_SESSION)) 
{ 
    $img = imageCreateFromPng($_GET['pic']); 
    header("Content-type: image/png"); 
    imagePng($img); 
    imagedestroy($img); 
} 

else 
{ 
    echo 'hidden'; 
    die; 
} 
?> 

我試圖隱藏從picture.php時產生的圖像會話未啓動。 我有其他的頁面命名show.php其中包含一個代碼

<?php 
    session_start(); 

    echo '<img src="picture.php?pic=apple.png" />' ; 
?> 

的問題是圖像不會show.php甚至會議節目開始顯示。 php爲什麼?

回答

0

如果你要檢查一些會話變量,然後不要忘了在上面

嘗試啓動會話:

<?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); 
} 
?> 

可以此幫助... start_session();

+0

無無無它生成使用** picture.php PIC = apple.png **就是我的形象呢?試圖做的是在** show.php **它會產生圖像,但加入URL ** picture.php?pic = apple.png **不會顯示它必須被隱藏的圖像。 – Detention

0

實際上,你可能想如果會話被認爲已經開始,則爲「flag」。

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" />' ;