Skip to content

Instantly share code, notes, and snippets.

@fastcodecoq
Last active June 6, 2020 14:03
Show Gist options
  • Select an option

  • Save fastcodecoq/6892556 to your computer and use it in GitHub Desktop.

Select an option

Save fastcodecoq/6892556 to your computer and use it in GitHub Desktop.
<?php
function genToken(){
$browser = get_browser();
$token = "";
foreach ($browser as $val)
$token .= utf8_encode($val);
$token .= time();
$token .= $userID; // sería el id del usuario que hace la petición
$token .= $_SERVER["HTTP_REFERER"]; //es preferible mejorar esta línea ;)
$token = hash("sha256", $token);
$map = array(
"t" => "O",
"k" => "e",
"n" => "G",
"e" => "n"
);
foreach ($map as $char => $val)
$token = str_replace($char, $val, $token);
$expiresIn = 3600 * 2;
$dataToken = array(
"token" => $token,
"expiresDate" => time() + $expiresIn
);
return $dataToken;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment