Results 1 to 8 of 8

Thread: Write to file problem - very weird.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    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.

  2. #2
    Member PBertie's Avatar
    Join Date
    Aug 2011
    Location
    Newcastle Upon Tyne
    Posts
    55

    Re: Write to file problem - very weird.

    Try:
    PHP Code:
    <?php
    $s 
    $_GET['s'];
    $shout_file $s.'.php';

    file_put_contents($shout_file$chat_lineFILE_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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    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!

  4. #4
    Member PBertie's Avatar
    Join Date
    Aug 2011
    Location
    Newcastle Upon Tyne
    Posts
    55

    Re: Write to file problem - very weird.

    How about:
    PHP Code:
    <?php
    $s 
    'Vital';
    $shout_file $s.'.php';

    file_put_contents($shout_file$chat_lineFILE_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 ']';
    ?>

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    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

  6. #6
    Member PBertie's Avatar
    Join Date
    Aug 2011
    Location
    Newcastle Upon Tyne
    Posts
    55

    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_lineFILE_APPEND);
      
    file_put_contents($shout_file$chat_lineFILE_APPEND);
    }
    else {
      
    file_put_contents($tester $chat_lineFILE_APPEND);
      
    file_put_contents($shout_file$chat_lineFILE_APPEND);
    }
    ?>

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    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

  8. #8
    Member PBertie's Avatar
    Join Date
    Aug 2011
    Location
    Newcastle Upon Tyne
    Posts
    55

    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
  •  



Click Here to Expand Forum to Full Width