Post: Client IP logged and saved to .txt Help
01-31-2016, 05:34 AM #1
Devious
Treasure hunter
(adsbygoogle = window.adsbygoogle || []).push({}); So im trying to make this code work and i watched several videos about this and i have no clue to what is the problem. heres the code.

    <?php

$IP = $_SERVER[“REMOTE_ADDR”];

$file = fopen “iplog.txt”;

$txtfile = fopen($file, “a”);

fwrite($txtfile, $IP);
fwrite($txtfile, “
“);
fclose($txtfile);
$message = “Your IP Has Been Logged It Is:”;
echo $message; echo $IP;
?>


I have the folder saved as ip.php and the iplog.txt next to the ip.php in the php folder
Help anyone?
01-31-2016, 05:48 AM #2
Winter
Purple God
Originally posted by Devious View Post
So im trying to make this code work and i watched several videos about this and i have no clue to what is the problem. heres the code.

    <?php

$IP = $_SERVER[“REMOTE_ADDR”];

$file = fopen “iplog.txt”;

$txtfile = fopen($file, “a”Winky Winky;

fwrite($txtfile, $IP);
fwrite($txtfile, “
Winky Winky;
fclose($txtfile);
$message = “Your IP Has Been Logged It Is:”;
echo $message; echo $IP;
?>


I have the folder saved as ip.php and the iplog.txt next to the ip.php in the php folder
Help anyone?


why is the code so ugly? can you even do a lot of the things you've done in it...

Since you're obviously retarded, I'm going to give you a simple example in C# which you should understand

    
string IP = "127.0.0.1";
IP = "";


edit: is this question serious?
Last edited by Winter ; 01-31-2016 at 05:52 AM.
01-31-2016, 05:52 AM #3
Dan
I'm a god.
Originally posted by Devious View Post
So im trying to make this code work and i watched several videos about this and i have no clue to what is the problem. heres the code.

    <?php

$IP = $_SERVER[“REMOTE_ADDR”];

$file = fopen “iplog.txt”;

$txtfile = fopen($file, “a”);

fwrite($txtfile, $IP);
fwrite($txtfile, “
“);
fclose($txtfile);
$message = “Your IP Has Been Logged It Is:”;
echo $message; echo $IP;
?>


I have the folder saved as ip.php and the iplog.txt next to the ip.php in the php folder
Help anyone?


    
<?php
$fp = fopen('data.txt', 'w'Winky Winky;
$ip = $_SERVER['REMOTE_ADDR'];
fwrite($fp, $ip);
fclose($fp);
01-31-2016, 05:53 AM #4
Winter
Purple God
Originally posted by Dan View Post
    
<?php
$fp = fopen('data.txt', 'w'Winky Winky;
$ip = $_SERVER['REMOTE_ADDR'];
fwrite($fp, $ip);
fclose($fp);


you shouldn't of told him.
01-31-2016, 06:12 AM #5
Shark
Retired.
Originally posted by Devious View Post
So im trying to make this code work and i watched several videos about this and i have no clue to what is the problem. heres the code.

    <?php

$IP = $_SERVER[“REMOTE_ADDR”];

$file = fopen “iplog.txt”;

$txtfile = fopen($file, “a”Winky Winky;

fwrite($txtfile, $IP);
fwrite($txtfile, “
Winky Winky;
fclose($txtfile);
$message = “Your IP Has Been Logged It Is:”;
echo $message; echo $IP;
?>


I have the folder saved as ip.php and the iplog.txt next to the ip.php in the php folder
Help anyone?


can't test on a server or anything but this seemed to work fine

    
<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$IP = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$IP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$IP = $_SERVER['REMOTE_ADDR'];
}

$fpath = realpath(dirname(__FILE__));
$file = $fpath."\iplog.txt";
$txtfile = fopen($file, "a");
fwrite($txtfile, $IP);
fclose($txtfile);
$message = "Your IP Has Been Logged It Is:";
echo $message; echo $IP;
?>
01-31-2016, 06:49 AM #6
Devious
Treasure hunter
Originally posted by Winter View Post
why is the code so ugly? can you even do a lot of the things you've done in it...

Since you're obviously retarded, I'm going to give you a simple example in C# which you should understand

    
string IP = "127.0.0.1";
IP = "";


edit: is this question serious?


Im not retarded. lel. Asking questions isnt something retarded unless you would want to be self learned and most of the times be unsure of things
01-31-2016, 08:03 AM #7
Devious
Treasure hunter
Originally posted by MEGALELZ
a) Error codes would have been nice.
b)

<?php
$ip = $_SERVER['REMOTE_ADDR'];

$myFile = "testFile.txt"; // this is your text file, call it something no one is going to find.

$fh = fopen($myFile, 'a'Winky Winky or die("can't open file"); // this opens the file, you can change what the die says.

$stringData = "Users IP: " . $ip . "\n"; // this is what will be in the file.

fwrite($fh, $stringData); // this writes to the file, while keeping what was also already there.

fclose($fh); // this closes the file.

echo "Your IP address has been logged.\n Your IP is: " . $ip;
?>


where would i put the .txt at?
01-31-2016, 11:41 PM #8
Devious
Treasure hunter
Originally posted by MEGALELZ
Same place as your PHP file.

You must login or register to view this content.
You must login or register to view this content.

If you wanted it in another folder you'd do

$myFile = "folder/testFile.txt";

So it'd be
You must login or register to view this content.

Understand?


Thank you liam :wub:
02-01-2016, 12:31 AM #9
Devious
Treasure hunter
Originally posted by MEGALELZ
Same place as your PHP file.

You must login or register to view this content.
You must login or register to view this content.

If you wanted it in another folder you'd do

$myFile = "folder/testFile.txt";

So it'd be
You must login or register to view this content.

Understand?


It still doesn't show any ips when i open the .txt i got everything correct i even reloaded the page for it to grab my ip however
it did say it was modified but no ip in the .txt

You must login or register to view this content.

You must login or register to view this content.

You must login or register to view this content.

there are no error codes
02-01-2016, 10:02 PM #10
Devious
Treasure hunter
Originally posted by MEGALELZ
Does it echo your IP address on the .php page?


Nope , it doesn't let me know what my ip is

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo