jacobsdad Posted January 1, 2007 Share Posted January 1, 2007 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 masterloggin.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.[code]<?phpsession_start();// file example 1: read a text file into an array, with // each line in a new element $filename="masterlogin.txt"; $lines = array(); $file = fopen($filename, "r"); while(!feof($file)) { //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");session_decode(fgets($sessionfile, 4096) );fclose($sessionfile);print "<a href=\"/php/".$lines[$i]."\">".$Lastname.", ".$Firstname."</a><br />";}//Create button to add more usersecho "<input type=\"button\" "; echo "value=\"Create Another User\" "; echo "onclick=\"location.href='loggin.html'\">";?> [/code] Link to comment https://forums.phpfreaks.com/topic/32429-solved-trying-to-open-sessions-while-in-a-loop/ Share on other sites More sharing options...
jacobsdad Posted January 2, 2007 Author Share Posted January 2, 2007 Just wondering if I have placed this question in the correct forum ... thanks for the help ...Michael Link to comment https://forums.phpfreaks.com/topic/32429-solved-trying-to-open-sessions-while-in-a-loop/#findComment-151162 Share on other sites More sharing options...
dbo Posted January 2, 2007 Share Posted January 2, 2007 So what is the problem exactly? You want to know how to assign your Username and Password variables in the code you displayed below? Link to comment https://forums.phpfreaks.com/topic/32429-solved-trying-to-open-sessions-while-in-a-loop/#findComment-151194 Share on other sites More sharing options...
jacobsdad Posted January 2, 2007 Author Share Posted January 2, 2007 I am trying to loop through all of the names of txt files in the masterlogin.txt file. I want to pull out the firstname and lastname of the users that created the file so that I can generate hyperlinks to those txt files. In the code that I have written the echo $lines[$i] will print out all of the titles inside the masterlogin file as LastnameFirstname.txt . If I take one of those text files and put it into the fopen argument that will create a hyperlink Lastname, Firstname for that particular user. It seems that the $lines[$i] is not putting the LastnameFirstname.txt into the fopen argument. Link to comment https://forums.phpfreaks.com/topic/32429-solved-trying-to-open-sessions-while-in-a-loop/#findComment-151205 Share on other sites More sharing options...
jacobsdad Posted January 2, 2007 Author Share Posted January 2, 2007 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 [color=red]trim([/color]$lines[$i][color=red])[/color] to make sure the text file names did not have any spaces or newlines has put me on the right track. Link to comment https://forums.phpfreaks.com/topic/32429-solved-trying-to-open-sessions-while-in-a-loop/#findComment-151267 Share on other sites More sharing options...
dbo Posted January 2, 2007 Share Posted January 2, 2007 Grats on finding it. Sorry I wasn't able to be anymore help. Link to comment https://forums.phpfreaks.com/topic/32429-solved-trying-to-open-sessions-while-in-a-loop/#findComment-151272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.