<?php

/* include hashids lib */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* create the class object with minimum hashid length of 8 */
$hashids = new Hashids\Hashids('this is my salt', 8);
/* encode several numbers into one id (length of id is going to be at least 8) */
$id = $hashids->encode(1337, 5);
/* decode the same id */
$numbers = $hashids->decode($id);
/* `$numbers` is always an array */
var_dump($id, $numbers);
exit;
Пример #2
1
Файл: Wash.php Проект: pean/wash
 protected function hashids($type, $str)
 {
     $hashids = new \Hashids\Hashids(md5($this->config['salt']));
     if ($type == 'decode') {
         return end($hashids->decode($str));
     } elseif ($type == "encode") {
         return $hashids->encode($str);
     }
 }
Пример #3
0
function addEntry($text, $title, $description)
{
    $success = false;
    $db = connectDB();
    $db->beginTransaction();
    $query = "INSERT INTO " . DB_TABLE . " (text_content,title,description) VALUES ( :text , :title , :desc )";
    $params = array(":text" => $text, ":title" => $title, ":desc" => $description);
    $rowCount = execute($db, $query, $params);
    if ($rowCount > 0) {
        $last_id = $db->lastInsertId();
        $hashids = new Hashids\Hashids('welcome to the salty splatoon how tough are ya');
        $hash = $hashids->encode($last_id);
        $editor_hash = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM));
        $query = "\n\t\tUPDATE " . DB_TABLE . "\n\t\tSET hash = :hash ,\n\t\t\teditor_hash = :ehash \n\t\tWHERE id = :id ";
        $params = array(":hash" => $hash, ":ehash" => $editor_hash, ":id" => $last_id);
        $rowCount = execute($db, $query, $params);
        if ($rowCount > 0) {
            $db->commit();
            $success = true;
        } else {
            $db->rollBack();
        }
    } else {
        $db->rollBack();
        //if ($last_id) execute($db,"DELETE FROM ".DB_TABLE." WHERE id = :id ",array(":id"=>$last_id));
    }
    close($db);
    if ($success) {
        return getEntryById($last_id);
    } else {
        return null;
    }
}
Пример #4
0
function generate_switchid($switch_name, $timestamp)
{
    $hashids = new Hashids\Hashids('embiggen');
    $hash = $hashids->encrypt(strlen($switch_name), $timestamp, 6);
    $numbers = $hashids->decrypt($hash);
    //!debug
    //var_dump($hash, $numbers);
    return $hash;
}
Пример #5
0
 public static function decodeHashID($salt, $hash_id)
 {
     $hashids = new Hashids\Hashids($salt, 10);
     $number = $hashids->decode($hash_id);
     //print_r($number);
     if (isset($number[0])) {
         return $number[0];
     } else {
         throw new Exception("Unable to decode hash_id");
     }
 }
function decodeSubscriber($subscriberHash)
{
    $hashids = new Hashids\Hashids(config('gtw.hashid.salts.subscribers'), 20, config('gtw.hashid.hash_chars'));
    $ids = null;
    try {
        $ids = $hashids->decode($subscriberHash);
    } catch (\Exception $e) {
    }
    if (count($ids) == 0) {
        return null;
    }
    return Subscriber::findOrFail($ids[0]);
}
Пример #7
0
 public function setFeaturedImage($article_id, $featured_image = null)
 {
     if ($featured_image) {
         $hashids = new Hashids\Hashids(HASHIDS_SALT);
         $id = $hashids->encode($article_id);
         $source = $featured_image['tmp_name'];
         $filename = 'article_' . $id . '_' . $featured_image['name'];
         $manager = new ImageManager();
         $upload_dir = PATH_PORTAL_CONTENT . '/featured/';
         $image = $manager->make($source);
         $image->save($upload_dir . $filename, 90);
         $data['featured_image'] = $filename;
         $this->db->where('id', $article_id);
         $this->db->update('artikel', $data);
         return $image->exif();
     } else {
         return FALSE;
     }
 }
 /**
  * Generates a new unique hash
  *
  * @return string - the new hash
  **/
 private function _generate_new_hash()
 {
     // Set up a new instance of hashids
     $hashids = new Hashids\Hashids(HASH_SALT, 1, $this->alphabet);
     // Set the default timezone
     date_default_timezone_set(TIMEZONE);
     // Get the daily count
     $dailycount = $this->_get_daily_count();
     // Let's check if the user passed in an ID to hash
     $passed_id = $this->_get_param('id');
     if ($passed_id) {
         $id = intval($passed_id . $dailycount);
     } else {
         // No id passed in?
         // Get the current timestamp as a number that represents YYMMDD
         // We'll append the daily count to it and use it as an ID
         $datestr = date('ymd');
         $id = intval($datestr . $dailycount);
     }
     // Generate the hash
     $hash = $hashids->encrypt($id);
     // Check to see if the hash is already in use
     if ($this->_does_hash_exist($hash)) {
         $this->_increment_daily_count();
         $this->_generate_new_hash();
     }
     return $hash;
 }
<?php

/* be sure to require `hashids` in your `composer.json` file first */
require_once __DIR__ . '/../vendor/autoload.php';
/* create the class object with custom alphabet */
$hashids = new Hashids\Hashids('this is my salt', 0, 'abcdefgh123456789');
/* encode several numbers into one id */
$id = $hashids->encode(1, 2, 3, 4);
/* decode the same id */
$numbers = $hashids->decode($id);
/* `$numbers` is always an array */
var_dump($id, $numbers);
exit;
Пример #10
0
}
function br2nl($s)
{
    return preg_replace('/\\<br(\\s*)?\\/?\\>/i', "\n", $s);
}
if (isset($_GET['upload'])) {
    if ($loggedin) {
        if (!empty($_FILES)) {
            $tFile = $_FILES['file']['tmp_name'];
            $fExt = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
            //$fName = sanitize($_FILES['file']['name']); //this file will be replaced if a matching file is uploaded
            /*$fName = str_replace("'", "", $fName);
            		$fName = str_replace('"', "", $fName);*/
            require 'includes/Hashids/HashGenerator.php';
            require 'includes/Hashids/Hashids.php';
            $hashids = new Hashids\Hashids('this is such a great salt', 8);
            $fName = strtotime(date("Y-m-d H:i:s"));
            $fName += gettimeofday()['usec'];
            $fName = $hashids->encode((int) $fName);
            $fHash = $fName;
            $fName .= '.' . $fExt;
            $targetPath = 'images/' . $fName;
            //this file will be replaced if a matching file is uploaded
            $fType = sanitize($_FILES['file']['type']);
            $fSize = sanitize($_FILES['file']['size']);
            //$mimeType = image_type_to_mime_type('IMAGETYPE_'.$fType);
            $mimeType = $fType;
            $date = ['last_modified' => date("F j, Y, g:i a"), 'today' => date("Y-m-d H:i:s")];
            $lmdf = $date['last_modified'];
            if (!file_exists($targetPath)) {
                if (move_uploaded_file($tFile, $targetPath)) {
Пример #11
0
<?php

/* be sure to require `hashids` in your `composer.json` file first */
require_once __DIR__ . '/../vendor/autoload.php';
/* create the class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encode several numbers into one id */
$id = $hashids->encode(45, 434, 1313, 99);
$nid = $hashids->encode(array(45, 434, 1313, 99));
/* `$id` is always a string */
var_dump($id);
var_dump($nid);
var_dump($id === $nid);
exit;
<?php

/* including hashids code */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* creating class object with custom alphabet */
$hashids = new Hashids\Hashids('this is my salt', 0, 'abcdefgh123456789');
/* encrypting several numbers into one hash */
$hash = $hashids->encrypt(1, 2, 3, 4);
/* decrypting the same hash */
$numbers = $hashids->decrypt($hash);
/* $numbers is always an array */
var_dump($hash, $numbers);
exit;
<?php

/* be sure to require `hashids` in your `composer.json` file first */
require_once __DIR__ . '/../vendor/autoload.php';
/* create the class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encode several numbers into one id */
$id = $hashids->encode(1337, 5, 77, 12345678);
/* decode that id back */
$numbers = $hashids->decode($id);
/* `$numbers` is always an array */
var_dump($id, $numbers);
exit;
<?php

/* including hashids code */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* creating class object with hash length of 8 */
$hashids = new Hashids\Hashids('this is my salt', 8);
/* encrypting several numbers into one hash (length of hash is going to be at least 8) */
$hash = $hashids->encrypt(1337, 5);
/* decrypting the same hash */
$numbers = $hashids->decrypt($hash);
/* $numbers is always an array */
var_dump($hash, $numbers);
exit;
Пример #15
0
<?php

require_once 'vendor/autoload.php';
// Change this to the number of ids you want to generate
$count = 10000;
$bench = new Ubench();
$bench->start();
$hashids = new Hashids\Hashids('4w3s0m3');
for ($i = 0; $i <= $count; $i++) {
    $encoded = $hashids->encode($i);
    // var_dump($encoded);
    $decoded = $hashids->decode($encoded);
}
$bench->end();
echo "\n# Hashids\n";
echo sprintf("Time: %s\n", $bench->getTime());
echo "\n============\n";
$bench->start();
$fakeId = new Guidsen\FakeIdentifier\Optimus(15468539, 1296427827, 340274557);
for ($i = 0; $i <= $count; $i++) {
    $encoded = $fakeId->encode($i);
    // var_dump($encoded);
    $decoded = $fakeId->decode($encoded);
}
$bench->end();
echo "\n# FakeIdentifier\n";
echo sprintf("Time: %s\n", $bench->getTime());
echo "============\n\n";
Пример #16
0
function submit_reg_form()
{
    //ReCaptcha
    $recaptcha = new ReCaptcha(RECAPTCHA_SECRET);
    $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
    if (!$resp->isSuccess()) {
        throw new Exception('Invalid captcha!');
    }
    //Get & Process form data
    $valid_inputs = 'name|email|tel|inst|std|day1|day2';
    foreach (get_presentations() as $key => $data) {
        $valid_inputs .= "|{$key}";
    }
    $form_data = getInputsWithKey($valid_inputs);
    //----Pricing
    //Count days
    $days = 0;
    for ($i = 1; $i <= 2; $i++) {
        if ($form_data["day{$i}"] != 'no') {
            $days++;
        }
    }
    $price = $days * 35;
    //    if ($days > 1)
    //        $price -= 10;
    //Discount
    $discount_rate = 0;
    if (isset($form_data['std'])) {
        switch ($form_data['std']) {
            case 'aut':
                $discount_rate = 0.6;
                break;
            case 'std':
                $discount_rate = 0.25;
                break;
        }
    }
    $price *= 1.0 - $discount_rate;
    $price = round($price);
    $form_data['price'] = $price;
    //Tel
    $form_data['tel'] = intval($form_data['tel']);
    //Generate tracking code
    $hashids = new Hashids\Hashids(HASHID_SALT);
    $tracking_code = $hashids->encode(time() . rand(0, 100));
    $form_data['code'] = $tracking_code;
    //Check Google Client Expired
    $token = json_decode(gapi_token, true);
    $client = new Google_Client();
    $client->setClientId(GAPI_CLIENT_ID);
    $client->setClientSecret(GAPI_CLIENT_SECRET);
    $client->setAccessToken(gapi_token);
    if ($client->isAccessTokenExpired()) {
        //Refresh on expire
        $client->refreshToken($client->getRefreshToken());
        foreach (json_decode($client->getAccessToken(), true) as $k => $v) {
            $token[$k] = $v;
        }
        file_put_contents(GAPI_TOKEN_LOCATION, "<?php define('gapi_token','" . json_encode($token) . "');");
    }
    //Get Registration sheet
    $serviceRequest = new DefaultServiceRequest($token['access_token']);
    ServiceRequestFactory::setInstance($serviceRequest);
    $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
    $sheet = $spreadsheetService->getSpreadsheets()->getByTitle('linuxfest_2015')->getWorksheets()->getByTitle('List');
    //Insert Submitted data
    $sheet->getListFeed()->insert($form_data);
    //Message
    $msg = "\n<div dir='rtl'>\n\n       با تشکر، ثبت نام آنلاین شما با موفقیت انجام شد و مورد بررسی قرار خواهد گرفت.\n        <br>\n        هزینه ی ثبت نام شما : <b>{$price}</b> هزار تومان\n                <br>\n        کد رهگیری شما : <b>{$tracking_code}</b>\n        (این کد را برای مراحل بعدی حتما نگهدارید)<br>\n        <br>\n                لطفا در اسرع وقت با مراجعه‌ی حضوری به دفتر انجمن علمی دانشکده هزینه‌ی دوره‌هایی را که در آن‌ها ثبت نام کرده‌اید پرداخت نمایید. در صورتی که مراجعه‌ی حضوری برایتان مقدور نیست هزینه‌ی ثبت نام را به کارت 5022291100266525 (بانک پاسارگاد به نام آرمین باشی‌زاده) واریز نمایید و کد رهگیری و شماره کارت خود را به آدرس hello@linuxfest.ir ارسال کنید. به دلیل محدود بودن ظرفیت کارگاه‌ها، اولویت با کسانی است که زودتر ثبت نام خود را نهایی کنند.\n<br>\nتهران، چهارراه ولی عصر، روبه‌روی خیابان بزرگمهر، دانشگاه صنعتی امیرکبیر ، دانشکده مهندسی کامپیوتر و فناوری اطلاعات ، دفتر انجمن علمی\n\t<br>\n     در صورت تمایل به ایجاد هرگونه تغییر در وضعیت ثبت نام خود از ثبت نام مجدد <b> جدا خودداری فرمایید</b>. در غیر این صورت ثبت نام شما تایید نخواهد شد.<br>\n      می‌توانید این تغییرات را از دو طریق ایمیل جشنواره hello@linuxfest.ir یا مراجعه‌ی حضوری اعلام فرمایید.\n\n</div>\n    ";
    $msg_2 = "جشنواره لینوکس امیرکبیر\n    هزینه ی ثبت نام : {$price} هزار تومان\n    کد رهگیری شما : {$tracking_code}\n    جهت ثبت نام نهایی در اسرع وقت به دفتر انجمن علمی دانشکده مراجعه فرمایید\n    ";
    //Email
    if (isset($form_data['email'])) {
        sendmail($form_data['email'], $msg);
    }
    //SMS
    if (isset($form_data['tel'])) {
        sendsms($form_data['tel'], $msg_2);
    }
    return $msg;
}
Пример #17
0
 /**
  * Converts the encryption key into an integer via base64todec, then transforms that into a unique ID via HashIds
  * @return string
  */
 public function getBaseHash()
 {
     $hashids = new Hashids\Hashids(Yii::app()->params['encryptionKey'], 8);
     $id = $hashids->encode($this->base62toDec(Yii::app()->params['encryptionKey']));
     return $id;
 }
Пример #18
0
 public function generateURLs($type, $n)
 {
     $baseurl = "http://wa.se/";
     if ($type == 'invalid') {
         $validchars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $invalidchars = '/+;:_!"#€%&/()=?';
         $validcharslen = strlen($validchars);
         $invalidcharslen = strlen($invalidchars);
         $urls = array();
         for ($i = 0; $i < $n; $i++) {
             $hash = '';
             $length = rand(1, 10);
             for ($j = 0; $j < $length; $j++) {
                 $hash .= $validchars[rand(0, $validcharslen - 1)];
                 $hash .= $invalidchars[rand(0, $invalidcharslen - 1)];
             }
             $urls[] = $baseurl . $hash;
         }
     } else {
         // Generate som valid urls
         $hashids = new \Hashids\Hashids(md5($this->config['salt']));
         $urls = array();
         for ($i = 0; $i < $n; $i++) {
             $int = rand(0, 1000000);
             $hash = $hashids->encode($int);
             $urls[] = $baseurl . $hash;
         }
     }
     return $urls;
 }
<?php

/* include hashids lib */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* create the class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encode several numbers into one id */
$id = $hashids->encode(45, 434, 1313, 99);
/* `$id` is always a string */
var_dump($id);
exit;
Пример #20
0
      </div>
    </div>
  </div>
  <div class="container">
<?php 
if ($errorMessage != '') {
    echo "<p>{$errorMessage}";
}
# Not sure if id < 1 is an accurate error flag — the create function
# doesn't say what happens if the write fails.
if ($newIssueId < 1) {
    print "\nSomething went wrong -- your request could not be submitted.";
} else {
    # Create a hashed link ID from the new issue number and the requestor's
    # email address (this can be de-hashed to retrieve the original values)
    $hashids = new Hashids\Hashids($cul_ini_array['hashid_salt']);
    $hash_array = encode_link($newIssueId, $_POST['submitter_email']);
    $link_id = $hashids->encode($hash_array);
    echo "<p>You have created request #{$newIssueId}: {$issueTitle}</p>";
    ?>
  <br><br><p>Thank you for submitting your request using the online Library Space Request Form.</p> 
  <p>It is your responsibility to check the status of your event by going to the following address and checking the list of approvers, their approval, and their comments about your event. If the approver requires more information about your event, please contact him/her immediately.</p>
  <p>Use the following link to access your request:

<?php 
    echo '<strong><a href="' . url_for_client($link_id) . '">' . url_for_client($link_id) . '</a></strong>';
    echo '<p>A confirmation email with this information will be sent to you shortly.</p>';
    echo '</div>';
    send_email($issueTitle, $_POST['submitter_email'], $newIssueId, $link_id);
}
function title($label)
Пример #21
0
 public function decode_ids($data)
 {
     $hashids = new \Hashids\Hashids();
     return $hashids->decode($data);
 }
<?php

/* including hashids code */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* creating class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encrypting several numbers into one hash */
$hash = $hashids->encrypt(1337, 5, 77, 12345678);
/* decrypting that hash */
$numbers = $hashids->decrypt($hash);
/* $numbers is always an array */
var_dump($hash, $numbers);
exit;
function hashCampaignEmail($campaignEmailId)
{
    $hashids = new Hashids\Hashids(config('gtw.hashid.salts.cmapaign_emails'), 20, config('gtw.hashid.hash_chars'));
    return $hashids->encode($campaignEmailId);
}
Пример #24
0
<?php

/* include hashids lib */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* create the class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encode one number */
$id = $hashids->encode(1337);
/* `$id` is always a string */
var_dump($id);
exit;
Пример #25
0
<?php

require_once 'vendor/autoload.php';
$hashids = new Hashids\Hashids('this is my salt', 10, 'abcdefghij1234567890');
$db = new mysqli("localhost", "root", "123456", 'iksdb3');
if (mysqli_connect_errno()) {
    print 'Error connect.' . "\n";
    exit;
}
$query = 'SELECT id,username FROM iksdb3.iksuser where username REGEXP "^[0-9]+$"';
$result = $db->query($query);
$num_results = $result->num_rows;
print "There are " . $num_results . ' results.' . "\n\n";
for ($i = 0; $i < $num_results; $i++) {
    $row = $result->fetch_assoc();
    $id = $row['id'];
    $username = $row['username'];
    $username_after = $hashids->encode($username);
    $query = 'update iksdb3.iksuser set username = "******" where id=' . $id;
    $result_update = $db->query($query);
    $affected_rows = $db->affected_rows;
    printf("%5d %s %s %d %d\n", $id, $username, $username_after, $result_update, $affected_rows);
}
$result->free();
$db->close();
<?php

/* including hashids code */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* creating class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encrypting several numbers into one hash */
$hash = $hashids->encrypt(45, 434, 1313, 99);
/* $hash is always a string */
var_dump($hash);
exit;
Пример #27
0
include "vendor/autoload.php";
function guid()
{
    if (function_exists('com_create_guid')) {
        return com_create_guid();
    } else {
        mt_srand((double) microtime() * 10000);
        //optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);
        // "-"
        $uuid = chr(123) . substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12) . chr(125);
        // "}"
        return $uuid;
    }
}
echo " . generating hash strings...\n";
echo str_repeat("=", $strLen + 3) . "\n";
for ($i = 0; $i < $strsNum; $i++) {
    $salt = guid();
    $ALPHABET = "abcdefghijklmnpqrstuvwxyz123456789";
    $hashids = new Hashids\Hashids($salt, $strLen, $ALPHABET);
    $id = $hashids->encode($i);
    printf("%02d %s\n", $i + 1, $id);
    // echo $i . " " . $id . "\n";
    // $numbers = $hashids->decode($id);
    // echo $this->guid();
    // var_dump($id, $numbers);
}
echo str_repeat("=", $strLen + 3) . "\n";
echo " . generate hash strings completed.\n\n";
Пример #28
0
function using_id_as_slug($post_id, $post = null)
{
    global $post_type;
    if ($post_type != 'page' && $post_type) {
        //只对文章生效
        // 如果是文章的版本,不生效
        if (wp_is_post_revision($post_id)) {
            return false;
        }
        // 取消挂载该函数,防止无限循环
        remove_action('save_post', 'using_id_as_slug');
        // 使用文章ID作为文章的别名
        $hashid = new Hashids\Hashids($post_type, 6, 'abcdefghijklmnopqrstuvwxyz0123456789');
        wp_update_post(array('ID' => $post_id, 'post_name' => $hashid->encode($post_id)));
        // 重新挂载该函数
        add_action('save_post', 'using_id_as_slug');
    }
}