0

we have just implemented an form on our intranet that allows anyone in IT (close to 100 people) the ability to tweet out to our users using a particular twitter account. Is there a way to store on the server or elsewhere who loaded the page at a particular time, or, even better, who filled in and submitted the form?

<div style="float: right; width: 450px; padding:20px;">
Use the box below to send out a tweet unrelated to the system status updates further down.<br />
<form name="MaffTwitterText" target="invisibleForm2" id="MaffTwitterText" action="./TweetText.php" method="post">
<textarea name="tweetMafftext" id="textarea" style="width:100%; height: 80px;" maxlength="140" placeholder="Enter your tweet here"></textarea>
<button type="submit" >
Click once only to send tweet
</button><br><iframe name="invisibleForm2" id="invisibleForm2" width="100px" height="25px" frameborder="0" scrolling="no"></iframe>
</form>
</div>

EDIT: revisiting this, What I was trying to achieve was to get a hidden variable within the form that contained the user's name (anonymous is disabled in IIS), looking back this was very badly worded as I didn't know what I was doing.

Maff
  • 23
  • 1
  • 6
  • 1
    Sure. Have them enter some identifier (name) and store it in the database along with the current timestamp (and probably the tweet also). – m59 Jan 21 '14 at 12:52
  • 1
    `Is there a way` - yep there is... – Nick R Jan 21 '14 at 12:55
  • you could store them in a database, export the tweet to a file, email it to an email address. There are quite a few options. As for working out who loaded the form and filled it in you would need either a login system where you could identify the user by who is logged in or provide a way for the user to specify who it is that is filling it in. As for a solution on how to do this its quite a bit of work if you want to go down somehting like the databse root. you would need a database table to store the data then the appropriate php controllers to save the data to the database. – azzy81 Jan 21 '14 at 12:55
  • on TweetText.php receive tweet via $_POST and get ip via $_SERVER['REMOTE_ADDR'], now store tweet,ip and timestamp in your db. – Pranay Bhardwaj Jan 21 '14 at 13:03

1 Answers1

2

If you are referring to getting the IP address of the user, just use the function from https://stackoverflow.com/questions/1437771/how-can-i-get-the-clients-ip-address-in-a-php-webservice:

public static function get_remote_ip() {
    if(isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR'])) {
        return $_SERVER['REMOTE_ADDR'];
    } 

    if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        return $_SERVER['HTTP_X_FORWARDED_FOR'];
    }

    return null;
}

Then just send that as a hidden variable and store it somewhere such as a mysqli database or a file including the tweet with it.

Community
  • 1
  • 1
Anonymous
  • 11,748
  • 6
  • 35
  • 57