2

目前我正在学习一些 Coldfusion 编码,我正在将我的整个旧 PHP 网站转换为时尚的 Coldfusion 代码,但我被几行 PHP 卡住了,我真的不知道我应该如何转换这些将代码行转换为正确的 Coldfusion 代码:

function access()   
{   
  $accesscode = $_GET["accesscode"];
  $time = (int)$_GET["time"];        
  $ip = $_GET["ip"];                

  // Time variable must be identical 
  if( time() < $time )  
      {  
      die("Locale time is ". (time()-$time) ."sec. is not correct.");  
      }  

 // Check client IP
  if( $ip <> $_SERVER["REMOTE_ADDR"] )  
      {  
      die("Client IP ".$_SERVER["REMOTE_ADDR"]." is not identical as ".$ip." used."); 
      }  

  // Time > 10 minutes is no access
  for ($c=0;$c<=3;$c++)   
    {   
    $t = substr(strftime("%Y%m%d%H%M", time()-($c*600)),0,11);   
    $hash = md5($ip. "9709f31be0". $t);   
    if( $hash == $accesscode ) return true;  
    }  

return false;  
}  

if (!access())      
{   
  die ("Access denied..");   
}   
Echo "Access approved.";  

如果有人可以帮我提供一些关于如何转换这些代码行的提示,我会非常高兴。

非常感谢提前,

4

1 回答 1

5

有几种方法可以做到……但我不得不做出一些假设,因为我对 php 不太了解。

<cffunction name="access" access="public" returntype="struct">
  <cfargument name="accesscode" type="string" required="yes">
  <cfargument name="time" type="string" required="yes">
  <cfargument name="ip" type="string" required="yes">

  <cfset var temp = StructNew()>
  <cfset temp.time = Now()>
  <cfset temp.errormsg = "">

  <cfif temp.time lt arguments.time>
     <cfset temp.errormsg = "(your error message here)">
  </cfif>

  <cfif cgi.remote_addr neq arguments.ip>
     <cfset temp.errormsg = "(your error message here)">
  </cfif>

  <cfloop index="temp.c" from="0" to="3">
     <!--- not entirely sure what you were doing in here --->
  </cfloop>


  <cfreturn temp>

</cffunction>

<cfset result = access(accesscode="something", time="something", ip="something")>

<cfif result.errormsg neq "">
   <!--- access denied --->
</cfif>
于 2012-10-03T14:09:27.100 回答