目前我正在学习一些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.";
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮我提供一些关于如何转换这些代码行的提示,我会非常感激.
非常感谢提前,
有几种方法你可以做到......但我不得不做一些假设,因为我不太了解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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1615 次 |
| 最近记录: |