Re: calling external php file before <html> tag

From: Ben (crescent_au_at_yahoo.com)
Date: 08/30/04


Date: 29 Aug 2004 18:46:07 -0700


"Wes Spikes" <MornThdr@NOSPAMverizon.net> wrote in message news:<3GdYc.640$O85.477@trnddc05>...
> include("file_path/file_name.php");
> function_name(arg1,arg2,[...],argX);
>
> Basically, you include the file, then call the function contained in the
> file.
>
Thanx Wes!

That's exactly what I did but it doesn't work...
My external php file is below (this sets a cookie):
<?php
 function counter() {
        $cookie_val = @$_COOKIE["user_ip"];
        $counterfile = "counter";
        $line = @file($conterfile);
        if(!$cookie_val) {
                setcookie("user_ip", "$_SERVER[REMOTE_ADDR]", time()+36000);
                if ($line[0] == NULL) {
                        $line[0] = 0;
                }
                $line[0]++;
                $cf = @fopen($counterfile, "w+");
                fputs($cf, "$line[0]");
                fclose($cf);
        }
        elseif ($cookie_val != "$_SERVER[REMOTE_ADDR]") {
                $line[0]++;
                $cf = @fopen($counterfile, "w+");
                fputs($cf, "$line[0]");
                fclose($cf);
        }
  }
?>

My main (calling) php file is like this:
<?php
  include 'phpfunc.php';
  counter();
?>
<html>
<head></head>
<body></body>
</html>

I get the following warning:
Warning: Cannot modify header information - headers already sent by
(output started at D:\Apache Group\Apache2\htdocs\phpfunc.php:26) in
D:\Apache Group\Apache2\htdocs\phpfunc.php on line 8

I also uncommented "include_path" in php.ini and added the path to my
localhost web server which is "D:\Apache Group\Apache2\htdocs\" but
nothing changed...

Hope this shows my problem more clearly..

Thanx!
Ben



Relevant Pages

  • Re: [PHP] Problem with Redirect
    ... Warning: Cannot modify header information - headers already sent ... You could also consider not doing a redirect at all, ...
    (php.general)
  • Re: PHP sessions and disabled cookies
    ... Cookies are blocked in my ... I do not see the URL containing the session ID. ... [PHP] ... A warning appears if the specified function is not defined, ...
    (php.general)
  • getting PHP5 sessions working when browser doesnt accept cookies.
    ... Here is my PHP ... The brower URL does not contain the session ID ... A warning appears if the specified function is not defined, ... support by the security team. ...
    (php.general)
  • session trouble
    ... everything else considering PHP is working perfectly and as far as I see ... the session tmp file is created in my tmp dir and I really don't see a valid ... A warning appears if the specified function is not defined, ... Setting certain environment variables may be a potential security breach. ...
    (alt.php)
  • Trouble with system() function
    ... PHP manual and have tried everything there, ... tried it on 2003 Server, ... You can redirect all of the output of your scripts to a function. ... A warning appears if the specified function is not defined, ...
    (comp.lang.php)