I would like to use session_decode while in a loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 2stepme@bellsouth.net

    #1

    I would like to use session_decode while in a loop

    I know I should be using a database ... but ... I have created a few
    pages which store user data in text files. The user text files where
    created using session_encode. There is a text file for each user.
    There is a masterlogin.txt that contains all of the names of the
    individual text files. I can loop through an array created from
    masterlogin.txt and create hyperlinks to each of the individual text
    files, but what I would like to do is while I am looping through the
    array I would like to open a session for each file, take out the names
    of the user so that I can have the hyperlink be Lastname, Firstname
    instead of the name of the text file. Any help on why this is not
    working will be greatly appreciated .... Thanks for the help ...
    Michael

    <?php
    session_start() ;
    // file example 1: read a text file into an array, with
    // each line in a new element

    $filename="mast erlogin.txt";
    $lines = array();
    $file = fopen($filename , "r");
    while(!feof($fi le)) {

    //read file line by line into a new array element
    $lines[] = fgets($file, 4096);

    }
    fclose ($file);

    //sort and creating variable for items in the array.
    sort($lines);
    $c = count($lines);

    //loop to print out hyperlink for each text file.
    for($i=0; $i<=$c; $i++)
    {

    $sessionfile = fopen($lines[$i], "r");
    global $firstname, $lastname;
    session_decode( fgets($sessionf ile, 4096) );
    fclose($session file);

    print "<a href=\"/php/".$lines[$i]."\">".$lastnam e.",
    ".$firstnam e."</a><br />";

    }

    ?>

  • 2stepme@bellsouth.net

    #2
    Re: I would like to use session_decode while in a loop

    I figured out what was causing my problem. While the variables that
    where created by the loop looked identical to the name of the text
    files they where not. Adding trim($lines[$i]) to make sure the text
    file names did not have any spaces or newlines has put me on the right
    track.


    2stepme@bellsou th.net wrote:
    I know I should be using a database ... but ... I have created a few
    pages which store user data in text files. The user text files where
    created using session_encode. There is a text file for each user.
    There is a masterlogin.txt that contains all of the names of the
    individual text files. I can loop through an array created from
    masterlogin.txt and create hyperlinks to each of the individual text
    files, but what I would like to do is while I am looping through the
    array I would like to open a session for each file, take out the names
    of the user so that I can have the hyperlink be Lastname, Firstname
    instead of the name of the text file. Any help on why this is not
    working will be greatly appreciated .... Thanks for the help ...
    Michael
    >
    <?php
    session_start() ;
    // file example 1: read a text file into an array, with
    // each line in a new element
    >
    $filename="mast erlogin.txt";
    $lines = array();
    $file = fopen($filename , "r");
    while(!feof($fi le)) {
    >
    //read file line by line into a new array element
    $lines[] = fgets($file, 4096);
    >
    }
    fclose ($file);
    >
    //sort and creating variable for items in the array.
    sort($lines);
    $c = count($lines);
    >
    //loop to print out hyperlink for each text file.
    for($i=0; $i<=$c; $i++)
    {
    >
    $sessionfile = fopen($lines[$i], "r");
    global $firstname, $lastname;
    session_decode( fgets($sessionf ile, 4096) );
    fclose($session file);
    >
    print "<a href=\"/php/".$lines[$i]."\">".$lastnam e.",
    ".$firstnam e."</a><br />";
    >
    }
    >
    ?>

    Comment

    Working...