Jopin Code

The Source..
Again, not as decent and squeaky clean as I d like it to be..

You will need to update your database information in the code:

Line 070:

$link = mysql_connect('Database_Server', 'Database_User', 'User_Password')

Where 'Database_Server' (or just localhost), 'Database_User' and 'User_Password' are your relevant database credentials or info..

Line 071:

mysql_select_db('jopin') or die('Could not select database');

You might replace 'jopin' with the database name of your choice

convert.pl


<?php

// Get Vars
$act = $_GET['act'];
$user = $_GET['id'];
$pass = $_GET['pass'];

loadSQL();

$act = mysql_real_escape_string($act);
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);

// Write in the Username
// $id = getID($user);

// Write in the R/W password checks

// Get, Put or Help!
// Get
if ($act == "get") {

 $id = getID($user, "get", $pass);
 print getIp($id);

// Put
} elseif ( ($act == "put") && ( $id = getID($user, "put", $pass))) {

 // Get ip & refip
 $ip = $_GET['ip'];
 $refip = $_SERVER['REMOTE_ADDR'];

 // Use refip if the ip is missing or corrupt
 if ( (! $ip) || (! ip2long($ip)) ) {
  $ip = $refip;
 }

 // Get the IP from the database
 $oldip = getIp($id);

 // Update the current record or Save a new one
 if ($oldip == $ip) {
  updateIP($id);
 } else {
  setIP($id, $ip, $refip);
 }

 print "Saving ". $ip . " for " . $user . " from " . $refip . " (formerly " . $oldip .")";

// GetPut Help
} else {
 help();
}

 unloadSQL();

// Functions
 
// Print help functions
function help() {
print "<ul>";
print "<li> index.php?act=get&id= </li>";
print "<li> index.php?act=put&id= &ip= </li>";
print "</ul>";
}

// Load the SQL settings
function loadSQL() {
 // Connecting, selecting database
 $link = mysql_connect('Database_Server', 'Database_User', 'User_Password')
     or die('Could not connect: ' . mysql_error());
 mysql_select_db('jopin') or die('Could not select database');
}

// Save IP to database
function setIP($id, $ip, $source) {
 $query = 'insert into data (id, ip, source, time) values ("'. $id .'", "'. $ip .'", "'. $source .'", now());';
 return mysql_query($query) or die('Query failed: ' . mysql_error());
}

// Update IP date to database
function updateIP($pID) {
# Update Timestamp
 $query = 'UPDATE data SET time=now() WHERE id ="' . $pID .'" ORDER BY time DESC LIMIT 1';
 return mysql_query($query) or die('Query failed: ' . mysql_error());
}

// Get user id IP from database
function getIp($pID) {
 // Performing SQL query
 $query = 'SELECT ip FROM data where id ="' . $pID .'" ORDER BY time DESC LIMIT 1';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());

 // Printing results in HTML
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  foreach ($line as $col_value) {
   $answer .= $col_value;
  }
 }
 return $answer;
}

// get user id from database
function getID($pID, $type, $pass) {

if ($type == "get") {
 $where = ' and readkey = "'. $pass .'"';
} elseif ($type == "put") {
 $where = ' and writekey = "'. $pass .'"';
}

 // Performing SQL query
 $query = 'SELECT id FROM user where name ="' . $pID .'" '. $where .' LIMIT 1';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());

 // Printing results in HTML
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  foreach ($line as $col_value) {
   $answer .= $col_value;
  }
 }
 return $answer;
}


// Clean up the SQL
function unloadSQL() {
 // Free resultset
 mysql_free_result($result);

 // Closing connection
 mysql_close($link);
}

?>

More about me

Site QR Code

Use this code at your own peril; I am not responsible for anything that happens to you or your devices. You re a big boy or girl, please do some research before using it if you have any concerns!