Page 1 of 1

Is it possible to carry an array forward to make a filename

Posted: Mon Feb 02, 2004 8:44 am
by andylyon87
I have a text box named $array[chat] in it is placed a random number, I would then like this number to be carried forward to the next page where the file created or accessed is the same name as the value of $array[chat].

script designed to write and read $array[chat]

Code: Select all

function WriteToFile($firstname){
         $str= "{$arrayї'chat']}.txt";
         $Open = fopen ($str,"a");
         if($Open){
                   fwrite ($Open,"$firstname");
                   fclose($Open);
                   $Worked=True;
         } else {
           $Worked = False;
          }
          return $Worked;
          }
function readfromfile(){
         $str =  "{$arrayї'chat']}.txt"; 
         $Open = fopen ($str,"r");
         if($Open){
         print("<HR><B><font color=white><a href="#latest" style=text-decoration:none>Comments:(To see the latest comment click here)</B></A><BR>\n");
         $data = file($str);
         for($n = 0; $n<count($data); $n++)&#123;
                $getline = explode("\t",$data&#1111;$n]);
                print("<B>$getline&#1111;0]\t$getline&#1111;1]<HR>\n");&#125;
                fclose($Open);
         &#125;else&#123;
               print("<font color=white><B>Unable to present previous comments!<HR><B><font color=white><a href="#latest" style=text-decoration:none>Comments:(To see the latest comment click here)</B></A><BR>\n");
               &#125;
&#125;

Posted: Tue Feb 03, 2004 1:16 am
by teniosoft
This seems like a resource intensive and complicated way of doing things I think that you should use some sort of data store using a database but, alas that is just my thought.


You could always do something like this

write the file the way that you are doing it

try header("location : filename.php") this will take you to that file but, it is going to fill up your server with a lot of junk files.

I think that looking at the way that other php chat servers may be a good idea too.