I have this code that reads a file created by Netscape HTTP Cookie File
, however I was only able to use the script and read the file of the user who is with the session username
open, I need to list all TXTS
and read all they without exception.
NOTE: The files have different names:
<?php
require_once getcwd() . '/modules/config.php';
$username = null;
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
}
$pointer = fopen(getcwd() . '/cookies/' . $username . '.txt', 'r');
while (!feof($pointer)) {
$row = fgets($pointer);
}
fclose($pointer);
How to read all files with different names other than the file with the name created in the session?
EDITED
In the comments Anderson cited the use of the glob()
function, I was able to read all the files with this code.
foreach (glob(getcwd() . '/cookies/*.txt') as $file) {
$pointer = fopen($file, 'r');
while (!feof($pointer)) {
$row[] = fgets($pointer);
}
}
var_dump($row);
But it contains unnecessary lines in the file, I need to get only the cookies
, look what returns me:
I need only cookies
, understand?