Re: [PHP] Urgent help - Token Generation code!
Let me try and get back. Thanks, Jasper! On 28-May-2011, at 4:29 AM, Jasper Mulder lord_fa...@hotmail.com wrote: From: shreya...@gmail.com To: lord_fa...@hotmail.com Subject: Re: [PHP] Urgent help - Token Generation code! Date: Sat, 28 May 2011 04:15:59 +0530 Jasper, Tried echoing $sToken but wouldn't work. Regards, Shreyas On 28-May-2011, at 4:11 AM, Jasper Mulder wrote: Date: Sat, 28 May 2011 03:56:26 +0530 From: shreya...@gmail.com To: php-general@lists.php.net Subject: [PHP] Urgent help - Token Generation code! I am re-visiting the world of PHP after a really big hiatus and I am finding things veryslippery. Can someone please help me with the below code and let me know how I can print the token that is getting generated? I am using EasyPHP and I am trying to echo the $token but it wouldn't print anything. I am trying it as : http://localhost/token/URLToken.php. May I know where all I am going wrong here in my approach? $sUrl = /tstd_c_b1@s54782; $sParam = primaryToken; $nTime = time(); $nEventDuration = 86400; $nWindow = $nTime + $nEventDuration; $sSalt = akamai123!; $sExtract = ; // optional As a second try, what happens if you add right here the line $sGen = urlauth_gen_url($sUrl, $sParam, $nWindow, $sSalt, $sExtract, $nTime); Because it seems as though you just declare three functions in the code without calling them... function urlauth_gen_url($sUrl, $sParam, $nWindow, $sSalt, $sExtract, $nTime) { $sToken = urlauth_gen_token($sUrl, $nWindow, $sSalt, $sExtract, $nTime); echo $token; There are two cases: 1. You made a typo and meant 'echo $sToken;' on the above line instead 2. You omitted the part where $token is defined and used [More code that seemed fine] -- Regards, Shreyas Agasthya Best regards, Jasper Mulder -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Urgent help - Token Generation code!
I am re-visiting the world of PHP after a really big hiatus and I am finding things veryslippery. Can someone please help me with the below code and let me know how I can print the token that is getting generated? I am using EasyPHP and I am trying to echo the $token but it wouldn't print anything. I am trying it as : http://localhost/token/URLToken.php. May I know where all I am going wrong here in my approach? ?php $sUrl = /tstd_c_b1@s54782; $sParam = primaryToken; $nTime = time(); $nEventDuration = 86400; $nWindow = $nTime + $nEventDuration; $sSalt = akamai123!; $sExtract = ; // optional function urlauth_gen_url($sUrl, $sParam, $nWindow, $sSalt, $sExtract, $nTime) { $sToken = urlauth_gen_token($sUrl, $nWindow, $sSalt, $sExtract, $nTime); echo $token; if ($sToken == null) { return ; } if (($sParam == ) || (!is_string($sParam))) { $sParam = __gda__; } if ((strlen($sParam) 5) || (strlen($sParam) 12)) { return; } if (($nWindow 0) || (!is_integer($nWindow))) { return; } if (($nTime = 0) || (!is_integer($nTime))) { $nTime = time(); } $nExpires = $nWindow + $nTime; if (strpos($sUrl, ?) === false) { $res = $sUrl . ? . $sParam . = . $nExpires . _ . $sToken; } else { $res = $sUrl . . $sParam . = . $nExpires . _ . $sToken; } return $res; } /** * Returns the hash portion of the token. This function should not be * called directly. */ function urlauth_gen_token($sUrl, $nWindow, $sSalt, $sExtract, $nTime) { if (($sUrl == ) || (!is_string($sUrl))) { return; } if (($nWindow 0) || (!is_integer($nWindow))) { return; } if (($sSalt == ) || (!is_string($sSalt))) { return; } if (!is_string($sExtract)) { $sExtract = ; } if (($nTime = 0) || (!is_integer($nTime))) { $nTime = time(); } $nExpires = $nWindow + $nTime; $sExpByte1 = chr($nExpires 0xff); $sExpByte2 = chr(($nExpires 8) 0xff); $sExpByte3 = chr(($nExpires 16) 0xff); $sExpByte4 = chr(($nExpires 24) 0xff); $sData = $sExpByte1 . $sExpByte2 . $sExpByte3 . $sExpByte4 . $sUrl . $sExtract . $sSalt; $sHash = _unHex(md5($sData)); $sToken = md5($sSalt . $sHash); return $sToken; } /** * Helper function used to translate hex data to binary */ function _unHex($str) { $res = ; for ($i = 0; $i strlen($str); $i += 2) { $res .= chr(hexdec(substr($str, $i, 2))); } return $res; } ? -- Regards, Shreyas Agasthya
RE: [PHP] Urgent help - Token Generation code!
From: lord_fa...@hotmail.com To: shreya...@gmail.com Subject: RE: [PHP] Urgent help - Token Generation code! Date: Sat, 28 May 2011 00:41:02 +0200 Date: Sat, 28 May 2011 03:56:26 +0530 From: shreya...@gmail.com To: php-general@lists.php.net Subject: [PHP] Urgent help - Token Generation code! I am re-visiting the world of PHP after a really big hiatus and I am finding things veryslippery. Can someone please help me with the below code and let me know how I can print the token that is getting generated? I am using EasyPHP and I am trying to echo the $token but it wouldn't print anything. I am trying it as : http://localhost/token/URLToken.php. May I know where all I am going wrong here in my approach? $sUrl = /tstd_c_b1@s54782; $sParam = primaryToken; $nTime = time(); $nEventDuration = 86400; $nWindow = $nTime + $nEventDuration; $sSalt = akamai123!; $sExtract = ; // optional function urlauth_gen_url($sUrl, $sParam, $nWindow, $sSalt, $sExtract, $nTime) { $sToken = urlauth_gen_token($sUrl, $nWindow, $sSalt, $sExtract, $nTime); echo $token; There are two cases: 1. You made a typo and meant 'echo $sToken;' on the above line instead 2. You omitted the part where $token is defined and used [More code that seemed fine] -- Regards, Shreyas Agasthya Best regards, Jasper Mulder I forgot to hit Reply All instead of Reply. I am deeply sorry for such a careless omission. Best regards, Jasper Mulder -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Urgent help - Token Generation code!
From: shreya...@gmail.com To: lord_fa...@hotmail.com Subject: Re: [PHP] Urgent help - Token Generation code! Date: Sat, 28 May 2011 04:15:59 +0530 Jasper, Tried echoing $sToken but wouldn't work. Regards, Shreyas On 28-May-2011, at 4:11 AM, Jasper Mulder wrote: Date: Sat, 28 May 2011 03:56:26 +0530 From: shreya...@gmail.com To: php-general@lists.php.net Subject: [PHP] Urgent help - Token Generation code! I am re-visiting the world of PHP after a really big hiatus and I am finding things veryslippery. Can someone please help me with the below code and let me know how I can print the token that is getting generated? I am using EasyPHP and I am trying to echo the $token but it wouldn't print anything. I am trying it as : http://localhost/token/URLToken.php. May I know where all I am going wrong here in my approach? $sUrl = /tstd_c_b1@s54782; $sParam = primaryToken; $nTime = time(); $nEventDuration = 86400; $nWindow = $nTime + $nEventDuration; $sSalt = akamai123!; $sExtract = ; // optional As a second try, what happens if you add right here the line $sGen = urlauth_gen_url($sUrl, $sParam, $nWindow, $sSalt, $sExtract, $nTime); Because it seems as though you just declare three functions in the code without calling them... function urlauth_gen_url($sUrl, $sParam, $nWindow, $sSalt, $sExtract, $nTime) { $sToken = urlauth_gen_token($sUrl, $nWindow, $sSalt, $sExtract, $nTime); echo $token; There are two cases: 1. You made a typo and meant 'echo $sToken;' on the above line instead 2. You omitted the part where $token is defined and used [More code that seemed fine] -- Regards, Shreyas Agasthya Best regards, Jasper Mulder -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php