Maff Maff - 1 year ago 73
HTML Question

Store who submitted a form?

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>

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.

Answer Source

If you are referring to getting the IP address of the user, just use the function from How can I get the client's 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.