PHP include problem? any idea?

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

    PHP include problem? any idea?

    Hi, I try to configure a php applic to load a config file (the purpose is to
    use in all the php pages variables definied in a config file)

    Here is a small example which describe my problem:

    My config file (test_config.ph p)
    <?
    $FOO=1;
    print "IN REQUIRE FILE: $FOO\n";
    ?>

    The page that require the config file:
    <?
    print "Hello<bR>\ n";
    require "test_config.ph p";
    #require "http://servername/test/test_config.php ";
    print "<br>FOO from config:$FOO<br> \n";
    ?>

    If I execute it, it works (until the file test_config can be found in the
    include_path var defined in the php.ini)
    The result is:
    ---------------
    Hello
    IN REQUIRE FILE: 1
    FOO from config:1
    ---------------

    If I comment the first require and uncomment the second one, PHP execute the
    file,
    but I can not use the variable ($FOO) definied in the config file
    The result is:
    ---------------
    Hello
    IN REQUIRE FILE: 1
    Notice: Undefined variable: FOO in E:\Web-repository\yca\ dns\test\1.php on
    line 5

    FOO from config:
    ---------------



  • Kolja Engelmann

    #2
    Re: PHP include problem? any idea?

    Quite easy solution:

    You can't require a file like that using windows, because:

    "Windows versions of PHP prior to PHP 4.3 do not support accessing
    remote files via this function, even if allow_url_fopen is enabled."

    Try a work around with fopen instead.

    Kolja

    Comment

    • hexkid

      #3
      Re: PHP include problem? any idea?

      Cartensy wrote...
      [...][color=blue]
      > My config file (test_config.ph p)
      > <?
      > $FOO=1;
      > print "IN REQUIRE FILE: $FOO\n";
      > ?>
      >
      > The page that require the config file:
      > <?
      > print "Hello<bR>\ n";
      > require "test_config.ph p";
      > #require "http://servername/test/test_config.php ";
      > print "<br>FOO from config:$FOO<br> \n";
      > ?>[/color]
      [...][color=blue]
      > If I comment the first require and uncomment the second one, PHP execute the
      > file,
      > but I can not use the variable ($FOO) definied in the config file
      > The result is:[/color]
      [...]

      What about changing test_config.php to
      <?php
      echo "<?php\n";
      echo " \$FOO = 1;\n";
      echo " print \"IN REQUIRE FILE: \$FOO\";\n";
      echo "?>";
      ?>
      in the remote server?


      Not tested ... just a crazy idea :-)



      --
      I have a spam filter working.
      To mail me include "urkxvq" (with or without the quotes)
      in the subject line, or your mail will be ruthlessly discarded.

      Comment

      Working...