将PHP代码转换为Coldfusion

时间:2012-10-03 13:46:08

标签: coldfusion

目前我正在学习一些Coldfusion编码,我正在将我整个旧的PHP网站转换为时尚的Coldfusion代码,但我坚持使用几行PH​​P,我真的不知道我是怎么回事应该将这些代码行转换为适当的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.";  

如果有人能帮忙给我一些关于如何转换这些代码行的提示,我会非常感激。

提前多多感谢,

1 个答案:

答案 0 :(得分: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>