Skip to content

Instantly share code, notes, and snippets.

@santosh
Created June 28, 2015 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santosh/3f9743c4c77e3bf0d997 to your computer and use it in GitHub Desktop.
Save santosh/3f9743c4c77e3bf0d997 to your computer and use it in GitHub Desktop.
Collect useragent and ipaddress data from friends. I created this note redirect script to do the same. They were pointed to this script saying that they will be shown a note they must read.
<?php
/*
@scriptName: noteredirect.php
@author: Santosh Kumar
@authorURL: http://sntsh.com
*/
// set the content type which is read by browser
header("Content-type: text/plain");
// must set the timezone so that you don't confuse about time later
date_default_timezone_set('Asia/Kolkata');
// define IP address and user agent
$ip = $_SERVER["REMOTE_ADDR"];
$ua = $_SERVER["HTTP_USER_AGENT"];
// define timestamp
$fulltime = strftime('%c');
// write them at once
$format = $ip . " __on__ " . $fulltime . " __with__ " . $ua . "\n\n";
// write them to file, NOTE: They must already have been created
$fp = fopen('noteredirect.txt', 'a');
fwrite($fp, $format);
fclose($fp);
// redirect to the real note.. or wherever
header("Location: https://twitter.com/sntshk");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment