#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Culver City, Ca
    Posts
    6
    Rep Power
    0
    I am trying to use this code to write to a text file the time ( in milliseconds) it takes to laod a page.

    <SCRIPT FOR=window EVENT=onload LANGUAGE="JScript">
    var StopTime = new Date();
    var TotalTime = (StopTime - StartTime);
    window.status = "Total time to load page was " + TotalTime;

    </SCRIPT>

    <?
    // open file for writing
    $myfile = fopen("data.txt","a");
    // write the file
    fputs($myfile, "line $TotalTimen");
    // close the file
    fclose($myfile);
    ?>

    <br><br>

    I get TotalTime to display in the status bar but the PHP file doesn't get created at all. If I run the PHP code stand-alone it works fine.

    Any clues?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    I am pretty sure that PHP cannot read the javascript variables since PHP happens before the page gets rendered to the browser and javascript starts after.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Culver City, Ca
    Posts
    6
    Rep Power
    0
    Oh darn.
    I was hoping that jumping into PHP would allow me to open & append to a text file. But, the file still doesn't get created unless I run the PHP routine as a seperate PHP script outside of a HTML document???

    Can opening & appending to a file be done just with JavaScript?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    No but you could probably use javascript to set a value of a form and then onload of the page submit the form to itself and use php code to open and append like :
    I am not very good with Javascript so I don't know if I am referenceing TotalTime correctly when I assign it to the form input.

    <SCRIPT FOR=window EVENT=onload LANGUAGE="JScript">
    var StopTime = new Date();
    var TotalTime = (StopTime - StartTime);
    window.status = "Total time to load page was " + TotalTime;
    document.theform.time.value = TotalTime;
    </SCRIPT>
    <body onLoad="document.theform.submit(); ">
    <?
    if (!$submit) {
    print '<form name="theform" action="'. $PHP_SELF .'" method="post">';
    print '<input type="hidden" name="time">';
    print '<input type="hidden" name="submit" value="submit">';
    print '</form>';
    }
    if ($submit) {
    // open file for writing
    $myfile = fopen("data.txt","a");
    // write the file
    fputs($myfile, "line $timen");
    // close the file
    fclose($myfile);
    }
    ?>
    </body>

Similar Threads

  1. writing to text file or xml?
    By webmorpheus in forum PHP Development
    Replies: 3
    Last Post: February 25th, 2005, 05:58 AM
  2. help with tables and wordwrapping
    By junkedBrian613 in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 06:42 PM
  3. Possible to read in value from a text file?
    By discus18 in forum PHP Development
    Replies: 2
    Last Post: February 7th, 2004, 12:19 AM
  4. Simple find and replace word search for a text file with php?
    By rabid lemming in forum PHP Development
    Replies: 4
    Last Post: February 1st, 2004, 10:37 PM
  5. How to read multiple line text file into a variable
    By gatewaycityca in forum Visual Basic Programming
    Replies: 4
    Last Post: January 29th, 2004, 01:26 PM

IMN logo majestic logo threadwatch logo seochat tools logo