-
Sep 11th, 2011, 01:09 PM
#1
Thread Starter
Fanatic Member
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.
-
Sep 11th, 2011, 02:38 PM
#2
Member
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.
-
Sep 11th, 2011, 03:18 PM
#3
Thread Starter
Fanatic Member
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!
-
Sep 11th, 2011, 03:47 PM
#4
Member
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 . ']'; ?>
-
Sep 11th, 2011, 03:54 PM
#5
Thread Starter
Fanatic Member
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
-
Sep 11th, 2011, 04:13 PM
#6
Member
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); } ?>
-
Sep 11th, 2011, 04:24 PM
#7
Thread Starter
Fanatic Member
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
-
Sep 11th, 2011, 04:44 PM
#8
Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|