Last active
June 6, 2020 14:03
-
-
Save fastcodecoq/6892556 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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