2009-06-16 32 views
2

我有一個基於PHP的應用程序正在運行。用戶登錄,並執行一些操作。我設置了一個反向代理來轉發某些僅由mochiweb服務器處理的請求 - 例如任何具有mysite.com/mochiweb的請求URL都會被路由到mochiweb服務器。用Mochiweb處理用戶會話

現在,我的問題是如何使用PHP發佈的會話信息對此請求進行身份驗證?我只希望通過PHP前端登錄的用戶能夠訪問mochiweb web服務器的服務。任何流浪的請求都不應該直接提供。

回答

1

你可以讓erlang服務器發送一個帶有上述會話cookie的http請求到php服務器,並且如果session有效或沒有返回php服務器。 例如這裏是我通過recaptcha驗證網站的方式

-module(ed_recaptcha). 

-license("GPL3"). 

-export([verify/4]). 

-define(RECAPTCHA_URL, "http://api-verify.recaptcha.net/verify"). 

verify(Private_Key, Remote_Ip, Challenge, Response) -> 
    Body = list_to_binary(
      io_lib:format(
       "privatekey=~s&challenge=~s&response=~s&remoteip=~s", 
       [Private_Key, Challenge, Response, Remote_Ip])), 
    case http:request(post, {?RECAPTCHA_URL, 
          [], "application/x-www-form-urlencoded", 
          Body}, 
         [{timeout, 30000}, {sync, false}], 
         []) of 
     {ok, {_Status_line, _Headers, Response_Body}} -> 
      verify_response(Response_Body) 
    end. 

verify_response("false\nincorrect-captcha-sol") -> 
    {error, robot}; 
verify_response("false\ninvalid-request-cookie") -> 
    {error, robot}; 
verify_response("true\nsuccess") -> 
    {ok, not_robot}.