problem with parsing

Discussion in 'PHP' started by dopex, May 1, 2008.

  1. #1
    i was wondering if it was possible to parse something from users local page. i really can't explain this very well. what i mean to say, is... on the top right of the forum, it says Welcome, *your username*. how could I parse *your username*. so if i were to embed it into a submit button, it would write dopex to a text file because thats my username, and if you were to hit it, it would write your username to a text file. thank you in advance.
     
    dopex, May 1, 2008 IP
  2. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So, you want basically a web form, that when submitted, will add a user's name to a list of other user's names in a text file (like a guestbook with text files)? Or each user would get their own individual text file?

    Which case you want to use will decide which direction you go in, but a general idea
    
    // name our variables
    $my_file  =  "my_file.txt";
    $my_user  =  $_POST['user_name'];
    
    // open the file for writing
    // "a" is the option to write to a file and/or create a file
    // don't use "w", lest you lose all your data
    //"r" won't create the file if it doesn't exist
    $handle = fopen($my_file, "a");
    
    // now we'll actually write our data to the file
    fwrite($handle, $my_user);
    
    // and now we'll "save" (eg, close) the file
    fclose($handle);
    Code (markup):
    Now, if that wasn't your question (reading your post a different way now) and you actually want to know how to parse out a user's name from a page (like a random forum page)... I have no idea. A whole lot of whacked out code. :p If it's your own forum (one that you have access to the code for), you'd just use whatever session variable is set (most forum documentation would tell you what it is).
     
    Altari, May 2, 2008 IP