/    Sign up×
Community /Pin to ProfileBookmark

Help with fwrite

Here is the php code:

[code=php]
$IPT = implode(”,file(‘ips.txt’));

$BMP = fopen(“ips.txt”,”w”);

$TY = “$IPT|$REMOTE_ADDR”;

fwrite($BMP, $TY);

fclose($BMP);
[/code]

Its supposed to open ips.txt then insert the current users IP to the end of the files contents. But instead it is placing blank boxes at the end of the files contents.

Here is the contents of ips.txt BEFORE the script is ran:

[CODE]|444.000.000.444|555.555.555.555[/CODE]

Here is the contents of ips.txt AFTER the script is ran:

[CODE]|444.000.000.444|555.555.555.555㙼⸵㠲㠲㜳ㄮ㤹[/CODE]

Can anyone see what I am doing wrong? ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 23.2009 — Where does $REMOTE_ADDR get set? Have you confirmed that it contains the expected value?
Copy linkTweet thisAlerts:
@NCA2authorFeb 23.2009 — Yes when I run it with echo $TY it shows:

ÿþ|444.000.000.444|555.555.555.555|81.85.252.178|65.28.137.99

Yet when I login through ftp and view he contents of ips.txt this is whats in it:

|444.000.000.444|555.555.555.555㡼⸱㔸㠷㠷ㄮ㠷㙼⸵㠲㜳㜳ㄮ㤹

I dont know why it is putting empty box looking things in place of the ips that the script is showing... nor do I know what this is: "ÿþ" that is outputed through http when the script is ran....
Copy linkTweet thisAlerts:
@MindzaiFeb 23.2009 — Which browser are you testing with? Have you tried echoing the contents of the variable using firefox?

Does it work correctly if you run the following?:

[code=php]
$IPT = implode('',file('ips.txt'));

$BMP = fopen("ips.txt","w");

$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
$TY = "$IPT|$REMOTE_ADDR";

fwrite($BMP, $TY);

fclose($BMP);
[/code]


It looks like the $REMOTE_ADDR variable is getting set with some extended characters somewhere, but its impossible to say without seeing the code which populates it.
Copy linkTweet thisAlerts:
@VodkaProDrinkerFeb 23.2009 — try to transform the codding of the document..

add in the head of the document:
[code=php]header('Content-Type: text/html; charset=UTF-8');[/code]
or try to use another charset.
×

Success!

Help @NCA2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...