I want to write some information in a txt file (user name, user mail and ip address) and then redirect to another html file. If I try to redirect nothing appears in the text file. But if I don't redirect to an html file the php script is working correctly. What am I missing?
<?php
$myfile = fopen("newfile.txt", "a") or die("Unable to open file!");
$txt1 = file_get_contents("newfile.txt");
$ip = get_client_ip_server();
$txt2 = $_COOKIE["userName"] ."\t" .$_COOKIE["userEmail"]." \t".$ip. "\r\n";
$txt3 = $txt1 . $txt2;
fwrite($myfile, $txt3);
fclose($myfile);
die();
header( "HTTP/1.0 302 Found" );
header( "Status: 302" ); # this is for chrome compliance
header( "Location: general.html" . $_SERVER["REQUEST_URI"] );
// Function to get the client ip address
function get_client_ip_server() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress =getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
?>
Thanks for your help