i beginner in php. uploaded text file on server , want write information within file using php. code working when run using xampp locally.
first call script using ajax (index.html):
$.ajax({ url: 'register.php', success: function (data) { // executed when ajax call finished window.location = "general.html"; }, error: function (xhr, status, error) { // executed if went wrong during call if (xhr.status > 0) alert('got error: ' + status); // status 0 - when load interrupted } });
then write information using php script:
<?php $myfile = fopen("user_information.txt", "a") or die("unable open file!"); $txt1 = file_get_contents("user_information.txt"); $ip = get_client_ip_server(); $txt2 = $_cookie["username"] ."\t" .$_cookie["useremail"]." \t".$ip. "\r\n"; $txt3 = $txt1 . $txt2; fwrite($myfile, $txt3); fclose($myfile); header( "http/1.0 302 found" ); header( "status: 302" ); # chrome compliance header( "location: general.html"); die(); // function 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; } ?>
the problem text file remains blank on server. think php script not executed. gave authorization write php file , text file.
thank help.
Comments
Post a Comment