Source Displayed With include_once()

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

    Source Displayed With include_once()

    I have just installed Apache 2.2 and PHP 5.1.4 on my Win XP Pro machine.
    If I run phpinfo(), it displays everything correctly. However, on a
    page where I have included a file that contains some functions, it
    merely shows the contents of the included file instead of running the
    function. For instance, I have a function called do_html_header( ) that
    does just what the name suggests, and I've used it for quite a while.

    The top of my page looks like this:

    <?php
    include_once("f unctions.php");

    do_html_header( "Terms");
    ?>

    However, when I view the page source, the actual PHP code is displayed,
    not just the HTML that it is supposed to display. It would seem that
    PHP is installed correctly since phpinfo() works fine. Is there
    something else I'm missing?

    Thanks.

    Steve
  • Benjamin Esham

    #2
    Re: Source Displayed With include_once()

    Steve wrote:
    The top of my page looks like this:
    >
    <?php
    include_once("f unctions.php");
    do_html_header( "Terms");
    ?>
    >
    However, when I view the page source, the actual PHP code is displayed,
    not just the HTML that it is supposed to display. It would seem that PHP
    is installed correctly since phpinfo() works fine. Is there something
    else I'm missing?
    It would seem that the file functions.php is not being interpreted as PHP
    code. Check your server settings to make sure that the file is placed in a
    suitable directory for inclusion.

    Also, you might make sure that your include file begins with <?php and ends
    with ?>. Otherwise, PHP has no way of knowing that your code is anything
    other than plain text.

    HTH,
    --
    Benjamin D. Esham
    bdesham@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
    "Given that sooner or later we're all just going to die, what's
    the point of learning about integers?" — Calvin

    Comment

    • Richard Levasseur

      #3
      Re: Source Displayed With include_once()


      Steve wrote:
      I have just installed Apache 2.2 and PHP 5.1.4 on my Win XP Pro machine.
      If I run phpinfo(), it displays everything correctly. However, on a
      page where I have included a file that contains some functions, it
      merely shows the contents of the included file instead of running the
      function. For instance, I have a function called do_html_header( ) that
      does just what the name suggests, and I've used it for quite a while.
      >
      The top of my page looks like this:
      >
      <?php
      include_once("f unctions.php");
      >
      do_html_header( "Terms");
      ?>
      >
      However, when I view the page source, the actual PHP code is displayed,
      not just the HTML that it is supposed to display. It would seem that
      PHP is installed correctly since phpinfo() works fine. Is there
      something else I'm missing?
      >
      Thanks.
      >
      Steve
      The only reason this would occur, that I can think of, is you don't
      have the opening tags in the functions.php file, "<?" or "<?php".

      Comment

      • jussist@gmail.com

        #4
        Re: Source Displayed With include_once()

        Similar thing happened to me on a new server. It was just a question of
        replacing '<?' with '<?php' . Bet a few bucks your case is the same.

        -----------------------
        Jussi


        Comment

        • Steve

          #5
          Re: Source Displayed With include_once()



          Benjamin Esham wrote:
          >
          It would seem that the file functions.php is not being interpreted as PHP
          code. Check your server settings to make sure that the file is placed in a
          suitable directory for inclusion.
          The included file is in the same directory as the page that is including
          it, and that's the way it worked in the past. Can included files only
          be in the directory specified in php.ini?
          >
          Also, you might make sure that your include file begins with <?php and ends
          with ?>. Otherwise, PHP has no way of knowing that your code is anything
          other than plain text.
          That was one of the first things I checked.

          Here are the first few lines from the functions.php:

          <?
          function do_html_header( $title)
          {
          // print an HTML header
          ?>
          <html>
          <head>
          <title>Shaw's Fiberglass - <?php echo $title ?></title>
          <meta http-equiv="Content-Type" content="text/html;">
          <meta name="keywords" content="fiberg lass,fenders,fr ont fenders,rear
          fenders,running boards,classic trucks,Chevy,Ch evrolet,General
          Motors,GMC,Jimm y,Shaws,Shawsfi berglass,truck, trucks,replacem ent,custom,1941 ,
          1942, 1943, 1944, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953,
          1954,antique,st reet rod,restored,tr uck parts,hood,hood s">
          <LINK REL=stylesheet HREF="shaw.css" TYPE="text/css">



          Here is the php code in the calling page:

          <?php
          include_once("f unctions.php");

          do_html_header( "Contact Us");
          ?>



          And here is what is displayed in view source:

          <?
          function do_html_header( $title)
          {
          // print an HTML header
          ?>
          <html>
          <head>
          <title>Shaw's Fiberglass - </title>
          <meta http-equiv="Content-Type" content="text/html;">
          <meta name="keywords" content="fiberg lass,fenders,fr ont fenders,rear
          fenders,running boards,classic trucks,Chevy,Ch evrolet,General
          Motors,GMC,Jimm y,Shaws,Shawsfi berglass,truck, trucks,replacem ent,custom,1941 ,
          1942, 1943, 1944, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953,
          1954,antique,st reet rod,restored,tr uck parts,hood,hood s">
          <LINK REL=stylesheet HREF="shaw.css" TYPE="text/css">

          Steve

          Comment

          • Benjamin Esham

            #6
            Re: Source Displayed With include_once()

            Steve wrote:
            Benjamin Esham wrote:
            >
            It would seem that the file functions.php is not being interpreted as
            PHP code. Check your server settings to make sure that the file is
            placed in a suitable directory for inclusion.
            >
            The included file is in the same directory as the page that is including
            it, and that's the way it worked in the past. Can included files only be
            in the directory specified in php.ini?
            AFAIK files can be included from any readable directory. Including a file
            from the same directory shouldn't cause any problems.
            Also, you might make sure that your include file begins with <?php and
            ends with ?>. Otherwise, PHP has no way of knowing that your code is
            anything other than plain text.
            >
            That was one of the first things I checked.
            >
            Here are the first few lines from the functions.php:
            >
            <?
            As another poster suggested, try using "<?php" instead of just "<?".

            HTH,
            --
            Benjamin D. Esham
            bdesham@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
            Ceci n'est pas une sig.

            Comment

            • Steve

              #7
              Re: Source Displayed With include_once()



              Benjamin Esham wrote:
              As another poster suggested, try using "<?php" instead of just "<?".
              >
              Something must definitely be wrong in my PHP setup. As soon as I change
              "<?" to "<?php" at the beginning of functions.php, nothing is
              displayed at all - even the view source is completely blank.

              Why would phpinfo() work, but it doesn't read this file correctly?

              Thanks.

              Steve

              Comment

              • Benjamin Esham

                #8
                Re: Source Displayed With include_once()

                Steve wrote:
                Benjamin Esham wrote:
                >
                As another poster suggested, try using "<?php" instead of just "<?".
                >
                Something must definitely be wrong in my PHP setup. As soon as I change
                "<?" to "<?php" at the beginning of functions.php, nothing is displayed at
                all - even the view source is completely blank.
                >
                Why would phpinfo() work, but it doesn't read this file correctly?
                I don't know. At the beginning of the include file, after the <?php but
                before any of the function definitions, insert

                echo '<h1>functions. php</h1>';
                phpinfo();

                When you run your script again you should see "functions. php" and the output
                from phpinfo(). If this doesn't appear, then your file is not being
                included. If it does appear, your problem lies somewhere in one of your
                functions or function calls.

                HTH,
                --
                Benjamin D. Esham
                bdesham@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
                "In the beginning the Universe was created. This has made a lot
                of people very angry and been widely regarded as a bad move."
                — Douglas Adams

                Comment

                • Shelly

                  #9
                  Re: Source Displayed With include_once()


                  "Steve" <racquetballer@ hotmail.comwrot e in message
                  news:lZmdnUqkY6 xyhUvZnZ2dnUVZ_ rmdnZ2d@comcast .com...
                  >
                  >
                  Benjamin Esham wrote:
                  >>
                  >It would seem that the file functions.php is not being interpreted as PHP
                  >code. Check your server settings to make sure that the file is placed in
                  >a
                  >suitable directory for inclusion.
                  >
                  The included file is in the same directory as the page that is including
                  it, and that's the way it worked in the past. Can included files only be
                  in the directory specified in php.ini?
                  >
                  >>
                  >Also, you might make sure that your include file begins with <?php and
                  >ends
                  >with ?>. Otherwise, PHP has no way of knowing that your code is anything
                  >other than plain text.
                  >
                  That was one of the first things I checked.
                  >
                  Here are the first few lines from the functions.php:
                  >
                  <?
                  function do_html_header( $title)
                  {
                  // print an HTML header
                  ?>
                  <html>
                  <head>
                  <title>Shaw's Fiberglass - <?php echo $title ?></title>
                  <meta http-equiv="Content-Type" content="text/html;">
                  <meta name="keywords" content="fiberg lass,fenders,fr ont fenders,rear
                  fenders,running boards,classic trucks,Chevy,Ch evrolet,General
                  Motors,GMC,Jimm y,Shaws,Shawsfi berglass,truck, trucks,replacem ent,custom,1941 ,
                  1942, 1943, 1944, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953,
                  1954,antique,st reet rod,restored,tr uck parts,hood,hood s">
                  <LINK REL=stylesheet HREF="shaw.css" TYPE="text/css">
                  >
                  >
                  >
                  Here is the php code in the calling page:
                  >
                  <?php
                  include_once("f unctions.php");
                  >
                  do_html_header( "Contact Us");
                  ?>
                  >
                  >
                  >
                  And here is what is displayed in view source:
                  >
                  <?
                  function do_html_header( $title)
                  {
                  // print an HTML header
                  ?>
                  <html>
                  <head>
                  <title>Shaw's Fiberglass - </title>
                  <meta http-equiv="Content-Type" content="text/html;">
                  <meta name="keywords" content="fiberg lass,fenders,fr ont fenders,rear
                  fenders,running boards,classic trucks,Chevy,Ch evrolet,General
                  Motors,GMC,Jimm y,Shaws,Shawsfi berglass,truck, trucks,replacem ent,custom,1941 ,
                  1942, 1943, 1944, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953,
                  1954,antique,st reet rod,restored,tr uck parts,hood,hood s">
                  <LINK REL=stylesheet HREF="shaw.css" TYPE="text/css">
                  >
                  Steve
                  Change the <? in the function page to <?php and see what happens.

                  Shelly


                  Comment

                  • Steve

                    #10
                    Re: Source Displayed With include_once()



                    Shelly wrote:
                    >Steve
                    >
                    Change the <? in the function page to <?php and see what happens.
                    >
                    Shelly
                    >
                    >
                    That's where the problem comes in. When I do, nothing is displayed -
                    the page is blank. Even the view source is blank. When it is just
                    "<?", it just displays the contents of the functions.php file, with no
                    processing.

                    Steve

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: Source Displayed With include_once()

                      Steve wrote:
                      >
                      >
                      Benjamin Esham wrote:
                      >
                      >As another poster suggested, try using "<?php" instead of just "<?".
                      >>
                      >
                      Something must definitely be wrong in my PHP setup. As soon as I change
                      "<?" to "<?php" at the beginning of functions.php, nothing is displayed
                      at all - even the view source is completely blank.
                      >
                      Why would phpinfo() work, but it doesn't read this file correctly?
                      >
                      Thanks.
                      >
                      Steve
                      Sounds like you might have a syntax error in your functions.php file.
                      First of all, enable all errors in your php.ini file:

                      error_reporting = E_ALL

                      Then either check your Apache error log file (if you're using the
                      default logging), or set

                      display_errors = On

                      in your php.ini file (not recommended for production systems) to see
                      what error you're getting.




                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Miguel Cruz

                        #12
                        Re: Source Displayed With include_once()

                        Steve <racquetballer@ hotmail.comwrot e:
                        Something must definitely be wrong in my PHP setup. As soon as I change
                        "<?" to "<?php" at the beginning of functions.php, nothing is
                        displayed at all - even the view source is completely blank.
                        You have solved one problem - changing <? to <?php was definitely
                        required, as evidenced by the fact that the value of $title was
                        correctly being output by do_html_header( ) in your earlier test, where
                        the file started with <? but later contained <?php echo $title ?>.

                        So now you have a different bug in your code which is preventing
                        anything from being displayed. However you haven't posted enough code
                        for us to figure out what that is.

                        miguel
                        --
                        Photos from 40 countries on 5 continents: http://travel.u.nu
                        Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
                        Airports of the world: http://airport.u.nu

                        Comment

                        • Steve

                          #13
                          Re: Source Displayed With include_once()



                          Jerry Stuckle wrote:
                          Sounds like you might have a syntax error in your functions.php file.
                          First of all, enable all errors in your php.ini file:
                          >
                          error_reporting = E_ALL
                          >
                          Then either check your Apache error log file (if you're using the
                          default logging), or set
                          >
                          display_errors = On
                          >
                          in your php.ini file (not recommended for production systems) to see
                          what error you're getting.
                          That did the trick. The problem was that whenever I started a PHP block
                          with "<?", it didn't work, but when I used "<?php", it works fine (I had
                          to do that in every place in functions.php).

                          I did a little more research, and discovered that the reason this was so
                          was that I had short_open_tags =Off in php.ini. I changed it to on, and
                          tested, and it worked the way I had it (with short tags).

                          Thanks for everybody's help. You learn something new every day.

                          Steve

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: Source Displayed With include_once()

                            Steve wrote:
                            >
                            >
                            Jerry Stuckle wrote:
                            >
                            >Sounds like you might have a syntax error in your functions.php file.
                            >First of all, enable all errors in your php.ini file:
                            >>
                            > error_reporting = E_ALL
                            >>
                            >Then either check your Apache error log file (if you're using the
                            >default logging), or set
                            >>
                            > display_errors = On
                            >>
                            >in your php.ini file (not recommended for production systems) to see
                            >what error you're getting.
                            >
                            >
                            That did the trick. The problem was that whenever I started a PHP block
                            with "<?", it didn't work, but when I used "<?php", it works fine (I had
                            to do that in every place in functions.php).
                            >
                            I did a little more research, and discovered that the reason this was so
                            was that I had short_open_tags =Off in php.ini. I changed it to on, and
                            tested, and it worked the way I had it (with short tags).
                            >
                            Thanks for everybody's help. You learn something new every day.
                            >
                            Steve
                            Steve,

                            It's better to run with short_open_tags off. Having it on will conflict
                            with other things.

                            One example is XML tags, which start with <?. With short_open_tags on,
                            the system will attempt to parse the XML as PHP, with understandably all
                            kinds of errors. It's one reason why the PHP developers recommend
                            turning off short tags - and why no one in this thread recommended
                            turning it on.


                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • Steve

                              #15
                              Re: Source Displayed With include_once()



                              Jerry Stuckle wrote:
                              Steve,
                              >
                              It's better to run with short_open_tags off. Having it on will conflict
                              with other things.
                              >
                              One example is XML tags, which start with <?. With short_open_tags on,
                              the system will attempt to parse the XML as PHP, with understandably all
                              kinds of errors. It's one reason why the PHP developers recommend
                              turning off short tags - and why no one in this thread recommended
                              turning it on.
                              >
                              >
                              That's fine. I will turn it back off. I just turned it on to verify that my theory was correct.

                              Steve

                              Comment

                              Working...