PHP/HTML displays garbage ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HarveyP

    #1

    PHP/HTML displays garbage ...

    I am using a PHPed version of an HTML file in order to include an
    onload function to write to a log file. The problem is that large parts
    of this file display as garbage 9 times out of 10, and sometimes again
    with a refresh.

    Question: Is this a HTML or a PHP problem? (it doesn't occur in my other
    HTML only pages)
    If it is a PHP problem, is it a question of delaying script execution
    until images are displayed? And how do I do that (or whatever else may
    need doing)?

    Thanks for any assistance
  • Sean

    #2
    Re: PHP/HTML displays garbage ...

    It's impossible to know where you are going wrong unless you post up
    some code.

    All php scripts are executed at server time all the html stuff is
    displayed on the client; so it's not possible to delay script
    execution until the images are displayed.

    Comment

    • HarveyP

      #3
      Re: PHP/HTML displays garbage ...

      In File oddsnsod.htms
      ....
      <META NAME="Date" CONTENT="2005-11-27" SCHEME="Year-Month-Day">
      <link rel="stylesheet "
      href="http://www.pearblossom house.com/mypages.css" type="text/css">
      <?php
      include '/home/pearblocom/public_html/php_scripts/log.php';
      ?>
      <script language="JavaS cript" TYPE="text/javascript">
      <!--
      function MM_swapImgResto re() { //v3.0
      ....

      In log.php
      ...
      <?php

      function iif($expression , $returntrue, $returnfalse = '') {
      return ($expression ? $returntrue : $returnfalse);
      }

      // Getting the information
      $ipaddress = $_SERVER['REMOTE_ADDR'];
      $page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
      $page .= iif(!empty($_SE RVER['QUERY_STRING']),
      "?{$_SERVER['QUERY_STRING']}", "");
      $referrer = $_SERVER['HTTP_REFERER'];
      $datetime = mktime();
      $useragent = $_SERVER['HTTP_USER_AGEN T'];
      $remotehost = @getHostByAddr( $ipaddress);

      // Create log line
      $logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' .
      $useragent . '|' . $remotehost . '|' . $page . "\n";

      // Write to log file:
      $logfile = sprintf('/home/username/public_html/logs/logs%d.txt',dat e('m'));

      // Open the log file in "Append" mode
      if (!$handle = fopen($logfile, 'ab')) {
      die("Failed to open log file");
      }

      // Write $logline to our logfile.
      if (fwrite($handle , $logline) === FALSE) {
      die("Failed to write to log file");
      }

      //close it all up
      fclose($handle) ;

      ?>
      ....

      So could I call log.php from the end of the file with better success?

      Sean wrote:
      [color=blue]
      >It's impossible to know where you are going wrong unless you post up
      >some code.
      >
      >All php scripts are executed at server time all the html stuff is
      >displayed on the client; so it's not possible to delay script
      >execution until the images are displayed.
      >
      >
      >[/color]

      Comment

      • Sean

        #4
        Re: PHP/HTML displays garbage ...

        OK, here is the simplest example I can think of.


        HarveyP wrote:[color=blue]
        > In File oddsnsod.htms
        > ...
        > <META NAME="Date" CONTENT="2005-11-27" SCHEME="Year-Month-Day">
        > <link rel="stylesheet "
        > href="http://www.pearblossom house.com/mypages.css" type="text/css">
        > <?php
        > include '/home/pearblocom/public_html/php_scripts/log.php';
        > ?>
        > <script language="JavaS cript" TYPE="text/javascript">
        > <!--
        > function MM_swapImgResto re() { //v3.0
        > ...[/color]

        This html and the php include are stored in a .htms file. I have never
        seen that type of file extension before but it doest matter. Is there
        something in your webserver configuration that tells the webserver to
        process .htms files with the php interpreter?? If not then the php
        include will not be executed and will simply just print to the screen.

        If you don't know what I am writing about then rename oddsnsod.htms
        to oddsnsod.php and try it.

        If the same thing is still happening then its because php is not
        enabled to work with your webserver.
        [color=blue]
        >
        > In log.php
        > ..
        > <?php
        >
        > function iif($expression , $returntrue, $returnfalse = '') {
        > return ($expression ? $returntrue : $returnfalse);
        > }
        >
        > // Getting the information
        > $ipaddress = $_SERVER['REMOTE_ADDR'];
        > $page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
        > $page .= iif(!empty($_SE RVER['QUERY_STRING']),
        > "?{$_SERVER['QUERY_STRING']}", "");
        > $referrer = $_SERVER['HTTP_REFERER'];
        > $datetime = mktime();
        > $useragent = $_SERVER['HTTP_USER_AGEN T'];
        > $remotehost = @getHostByAddr( $ipaddress);
        >
        > // Create log line
        > $logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' .
        > $useragent . '|' . $remotehost . '|' . $page . "\n";
        >
        > // Write to log file:
        > $logfile = sprintf('/home/username/public_html/logs/logs%d.txt',dat e('m'));
        >
        > // Open the log file in "Append" mode
        > if (!$handle = fopen($logfile, 'ab')) {
        > die("Failed to open log file");
        > }
        >
        > // Write $logline to our logfile.
        > if (fwrite($handle , $logline) === FALSE) {
        > die("Failed to write to log file");
        > }
        >
        > //close it all up
        > fclose($handle) ;
        >
        > ?>
        > ...[/color]

        All that looks ok. But your using allot of absolute addresses, you can
        make things easier on yourself by using relative ones.

        Comment

        • HarveyP

          #5
          Re: PHP/HTML displays garbage ...

          sorry tryping error - oddsnsods.html

          AND

          I have found tonight that my non PHP, HTML only pages are suffering too.
          Is it an ADSL thing? I am new to high speed downloading.


          Sean wrote:
          [color=blue]
          >OK, here is the simplest example I can think of.
          >
          >
          >HarveyP wrote:
          >
          >[color=green]
          >>In File oddsnsod.htms
          >>...
          >><META NAME="Date" CONTENT="2005-11-27" SCHEME="Year-Month-Day">
          >><link rel="stylesheet "
          >>href="http://www.pearblossom house.com/mypages.css" type="text/css">
          >><?php
          >> include '/home/pearblocom/public_html/php_scripts/log.php';
          >>?>
          >><script language="JavaS cript" TYPE="text/javascript">
          >><!--
          >>function MM_swapImgResto re() { //v3.0
          >>...
          >>
          >>[/color]
          >
          >This html and the php include are stored in a .htms file. I have never
          >seen that type of file extension before but it doest matter. Is there
          >something in your webserver configuration that tells the webserver to
          >process .htms files with the php interpreter?? If not then the php
          >include will not be executed and will simply just print to the screen.
          >
          >If you don't know what I am writing about then rename oddsnsod.htms
          >to oddsnsod.php and try it.
          >
          >If the same thing is still happening then its because php is not
          >enabled to work with your webserver.
          >
          >
          >[color=green]
          >>In log.php
          >>..
          >><?php
          >>
          >>function iif($expression , $returntrue, $returnfalse = '') {
          >> return ($expression ? $returntrue : $returnfalse);
          >>}
          >>
          >>// Getting the information
          >>$ipaddress = $_SERVER['REMOTE_ADDR'];
          >>$page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
          >>$page .= iif(!empty($_SE RVER['QUERY_STRING']),
          >>"?{$_SERVER['QUERY_STRING']}", "");
          >>$referrer = $_SERVER['HTTP_REFERER'];
          >>$datetime = mktime();
          >>$useragent = $_SERVER['HTTP_USER_AGEN T'];
          >>$remotehost = @getHostByAddr( $ipaddress);
          >>
          >>// Create log line
          >>$logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' .
          >>$useragent . '|' . $remotehost . '|' . $page . "\n";
          >>
          >>// Write to log file:
          >>$logfile = sprintf('/home/username/public_html/logs/logs%d.txt',dat e('m'));
          >>
          >>// Open the log file in "Append" mode
          >>if (!$handle = fopen($logfile, 'ab')) {
          >> die("Failed to open log file");
          >>}
          >>
          >>// Write $logline to our logfile.
          >>if (fwrite($handle , $logline) === FALSE) {
          >> die("Failed to write to log file");
          >>}
          >>
          >>//close it all up
          >>fclose($handl e);
          >>
          >>?>
          >>...
          >>
          >>[/color]
          >
          >All that looks ok. But your using allot of absolute addresses, you can
          >make things easier on yourself by using relative ones.
          >
          >
          >[/color]

          Comment

          • HarveyP

            #6
            Re: PHP/HTML displays garbage ...

            Sorry, dyslexic keyboard last 2 posts ...

            oddsnsods.php (not html or htms ...)

            The absolute addressing is because I also call log.php from a file in
            another directory, hence the PHP_SELF reference. I bought the original
            design of the site and have been messing about with it since I gained
            full access., but rearranging the whole file structure is something I
            haven't got around to yet

            Worse yet, I surfed one of my other, non PHP pages tonight and found the
            same problem! Perhaps it is an ADSL thing - I am new to high speed
            downloading ...

            Apologies for posting in the wrong forum. I shall start this thread
            again in a HTML forum, or an ADSL forum.

            Thanks for your time.

            Sean wrote:
            [color=blue]
            >OK, here is the simplest example I can think of.
            >
            >
            >HarveyP wrote:
            >
            >[color=green]
            >>In File oddsnsod.htms
            >>...
            >><META NAME="Date" CONTENT="2005-11-27" SCHEME="Year-Month-Day">
            >><link rel="stylesheet "
            >>href="http://www.pearblossom house.com/mypages.css" type="text/css">
            >><?php
            >> include '/home/pearblocom/public_html/php_scripts/log.php';
            >>?>
            >><script language="JavaS cript" TYPE="text/javascript">
            >><!--
            >>function MM_swapImgResto re() { //v3.0
            >>...
            >>
            >>[/color]
            >
            >This html and the php include are stored in a .htms file. I have never
            >seen that type of file extension before but it doest matter. Is there
            >something in your webserver configuration that tells the webserver to
            >process .htms files with the php interpreter?? If not then the php
            >include will not be executed and will simply just print to the screen.
            >
            >If you don't know what I am writing about then rename oddsnsod.htms
            >to oddsnsod.php and try it.
            >
            >If the same thing is still happening then its because php is not
            >enabled to work with your webserver.
            >
            >
            >[color=green]
            >>In log.php
            >>..
            >><?php
            >>
            >>function iif($expression , $returntrue, $returnfalse = '') {
            >> return ($expression ? $returntrue : $returnfalse);
            >>}
            >>
            >>// Getting the information
            >>$ipaddress = $_SERVER['REMOTE_ADDR'];
            >>$page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
            >>$page .= iif(!empty($_SE RVER['QUERY_STRING']),
            >>"?{$_SERVER['QUERY_STRING']}", "");
            >>$referrer = $_SERVER['HTTP_REFERER'];
            >>$datetime = mktime();
            >>$useragent = $_SERVER['HTTP_USER_AGEN T'];
            >>$remotehost = @getHostByAddr( $ipaddress);
            >>
            >>// Create log line
            >>$logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' .
            >>$useragent . '|' . $remotehost . '|' . $page . "\n";
            >>
            >>// Write to log file:
            >>$logfile = sprintf('/home/username/public_html/logs/logs%d.txt',dat e('m'));
            >>
            >>// Open the log file in "Append" mode
            >>if (!$handle = fopen($logfile, 'ab')) {
            >> die("Failed to open log file");
            >>}
            >>
            >>// Write $logline to our logfile.
            >>if (fwrite($handle , $logline) === FALSE) {
            >> die("Failed to write to log file");
            >>}
            >>
            >>//close it all up
            >>fclose($handl e);
            >>
            >>?>
            >>...
            >>
            >>[/color]
            >
            >All that looks ok. But your using allot of absolute addresses, you can
            >make things easier on yourself by using relative ones.
            >
            >
            >[/color]

            Comment

            Working...