PHP sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Kestas wrote:Thanks a lot!
Now it's all clear to me. All that I needed was "everything in PHP is compiled BEFORE the user sees ANYTHING on their screen"(by Jenk).
OF course... it's server-side, silly! :D
Kestas
Forum Newbie
Posts: 14
Joined: Mon Jul 31, 2006 12:10 am
Location: Lithuania

Post by Kestas »

I know it`s server-side, but thought output is being sent during compilation. As I understood now, php sends it only after EVERYTHING is compiled.
Kestas
Forum Newbie
Posts: 14
Joined: Mon Jul 31, 2006 12:10 am
Location: Lithuania

Post by Kestas »

Thanks everyone, it works now. The solution was:

index.php

Code: Select all

<?php 
session_start(); 
header("Content-type: image/jpeg"); 
$maindir="C:/web/docs/sventes/saskrydis/thumbs/"; 
$mydir = opendir($maindir);
$_SESSION["directory"]=$maindir;  
$exclude = array(".", "..", "Thumbs.db") ; 
$list=array();
$i=0;
while($fn = readdir($mydir)) { 
  if (!in_array($fn, $exclude)) { 
    $list[$i]=$fn;  
    echo "$fn<br />"; 
    $_SESSION["list"]=$list;
    echo'<img src="next.php?id='.$i.'"/><br>'; 
    $i++;
  } 
}
closedir($mydir);
?>
next.php:

Code: Select all

<?php 
session_start(); 
readfile($_SESSION["directory"].$_SESSION["list"][$id]);  
?>
Post Reply