Write to file problem - very weird.
Hi guys, i have a problem.. basically this is my part of my code
Code:
<?php
$s = $_GET['s'];
$shout_file ="$s.php"
file_put_contents($shout_file, $chat_line, FILE_APPEND);
what my aim is is so that when a user goes to mysite.com?s=chatroom1
the chatroom will write the message to $shout_file
(chatroom1.php)
same if they go to ?s=chatroom2
e,t,c
now the issue is, that its not writing to the $shout_file but it defo is getting the ?s= cause if i put print $s;
it prints it to the page... which is odd
but if i change it to $shout_file ="chatroom1.php"
it works perfect..
Any ideas why?
Thanks,
Jamie.
Re: Write to file problem - very weird.
Try:
PHP Code:
<?php
$s = $_GET['s'];
$shout_file = $s.'.php';
file_put_contents($shout_file, $chat_line, FILE_APPEND);
?>
There wasn't a ; on the end of the line too but I'm guessing that was a typo in here because that would have gave you an error.
Re: Write to file problem - very weird.
Same thing, this is so weird!!
if i put
$shout_file = "Vital.php";
it works and writes to Vital.php
but even when i put
$shout_file = $s.'.php';
it dont write to Vital.php
(P.s 0 my url is ?s=Vital) so i dont understand where the issue is coming from!
Re: Write to file problem - very weird.
How about:
PHP Code:
<?php
$s = 'Vital';
$shout_file = $s.'.php';
file_put_contents($shout_file, $chat_line, FILE_APPEND);
?>
If that works then I'm thinking your input isn't strictly "Vital". Try something like the following to check there is no trailing spaces:
PHP Code:
<?php
$s = $_GET['s'];
$shout_file = $s.'.php';
echo '[' . $shout_file . ']';
?>
Re: Write to file problem - very weird.
This is so weird,
that dont work either it
but when i do
echo '[' . $shout_file . ']';
it echos right Vital.php
but still isnt writing to the file.... this is weird.
any ideas?
Cheers,
Jamie
Re: Write to file problem - very weird.
What happening with this code?
Id expect it will either output true and write to the file twice or false and not write only once.
If you get false there is something wrong with the input string.
PHP Code:
<?php
$s = $_GET['s'];
$shout_file = $s.'.php';
$tester = 'Vital.php';
echo ($tester == $shout_file);
if ($tester == $shout_file) {
file_put_contents($tester , $chat_line, FILE_APPEND);
file_put_contents($shout_file, $chat_line, FILE_APPEND);
}
else {
file_put_contents($tester , $chat_line, FILE_APPEND);
file_put_contents($shout_file, $chat_line, FILE_APPEND);
}
?>
Re: Write to file problem - very weird.
That worked and showed the number 1 :S
im lost
wys it work there but not on my script above :S
Re: Write to file problem - very weird.
Showed 1 (true) and updated the file twice or just once? If twice then it suggests the url was not correct the other times.