Hi, everybody:

I have written an include file in my php file "main.php", with and include "ip.php", which is:

<?php
function getRealIpAddr()
{
if (!empty($_SERVER)){ //check ip from share internet
$ip=$_SERVER;
}
elseif (!empty($_SERVER)){ //to check ip is pass from proxy
$ip=$_SERVER;
}
else{
$ip=$_SERVER;
}
return $ip;
}
?>

My "main.php" is:

<?php
include("ip.php");
...
setcookie("US", $one.$two, $expire);
...
>

When I execute it, the "setcookie" gives me the error: "Warning: Cannot modify header information - headers already sent by (output started at .../ip.php:21) in .../main.php on line 402"
The header is supposed to be set in line 21, but line 21 does not exist!!!
Any help?

Thank you,

Xagutxu

Thank you, codewall. It has been very helpful for me.
The fact is that I had a blank line in the end of the library-function. So, it was printing a line, which is incompatible with the posterior header-settings. It is a little detail, but very important conceptually.

Thank you again,

Xagutxu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.