Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. $user = "username";
  4. $pass= "secret";
  5. $pu239_db = "dev";
  6. $old_db = "temp";
  7. $host = "localhost";
  8.  
  9. if ($user === 'username' || $pass === 'secret') {
  10.     die("please edit this file\n");
  11. }
  12.  
  13. $link = mysqli_connect("$host", "$user", "$pass", "$pu239_db") or die("Error " . mysqli_error($link));
  14.  
  15. $sql = "SELECT * FROM $old_db.user ORDER BY userid";
  16. $rs = $link->query($sql);
  17. $i = 0;
  18. while ($row = mysqli_fetch_assoc($rs)) {
  19.     $username = sqlesc($row['username']);
  20.     $email = sqlesc($row['email']);
  21.     $added = (int)$row['joindate'];
  22.     $last_login = (int)time();
  23.     $last_access = (int)time();
  24.     $time_offset = sqlesc($row['timezoneoffset']);
  25.     $birthday = sqlesc($row['birthday_search']);
  26.     $ip = '0x' . bin2hex(inet_pton($row['ipaddress']));
  27.     $passhash = sqlesc(bin2hex(random_bytes(32)));
  28.     $torrent_pass= sqlesc(bin2hex(random_bytes(32)));
  29.     $auth = sqlesc(bin2hex(random_bytes(32)));
  30.     $apikey = sqlesc(bin2hex(random_bytes(32)));
  31.     $status = sqlesc('confirmed');
  32.     $sql = "INSERT IGNORE INTO users (username, email, added, last_login, last_access, time_offset, birthday, ip, passhash, torrent_pass, auth, apikey, status)
  33.            VALUES ($username, $email, $added, $last_login, $last_access, $time_offset, $birthday, $ip, $passhash, $torrent_pass, $auth, $apikey, $status)";
  34.     echo $sql . "\n";
  35.     if ($link->query($sql)) {
  36.         $i++;
  37.     }
  38. }
  39.  
  40. echo "$i users imported\n";
  41.  
  42. function sqlesc($x)
  43. {
  44.     global $link;
  45.     if (is_integer($x)) return (int)$x;
  46.     return sprintf('\'%s\'', mysqli_real_escape_string($link, $x));
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement