2011-03-12 77 views
0

我有一個2字段的表格 用戶名: 密碼: 和一個提交按鈕。 用戶將輸入他的遠程網站(不是我的網站或我的域名,例如Gmail.com)的用戶名和密碼。 我想要一旦他點擊提交按鈕。一個jQuery腳本檢查這些在gmail.com上的登錄信息,並返回result.they是錯誤或工作登錄。並通知用戶是否登錄錯誤,但如果登錄信息良好,表單將提交。如何使用jQuery檢查遠程網站的登錄信息

我不太瞭解jQuery,但我很擅長php。我的搜索發現,爲了做到這一點,我需要通過在我的jQuery腳本和遠程域之間使用php代理來進行跨域腳本編寫。 我還發現simple php proxy。這看起來不錯。但我不知道如何使jQuery的東西,連接所有這一切。

更新:我發現這個代碼,但它不工作。

$('#submitbutton').attr('disabled', true); 
            $.post('/proxy.php?mode=json&nofollow=1&save_cookies=1&full_status=1&url=https://secure.dooom.com/login/login/', 
            { 
             username:$('#Name').val(), 
             password:$('#Password').val(), 
             password_strength:"strong" 
            }, function(data) { 
             if(data.status.http_code == "301"){ 
              $.get('/proxy.php', 
              { 
               mode: 'json', 
               cookie_file: data.cookie_file, 
               full_status: 1, 
               remove_cookies: 1, 
               //url: 'http://www.dooom.com/store/index/' 
               url: 'http://www.dooom.com/store/index/?action=add_to_cart&products_id=3263691&is_subscription=1&freq=1&term=getstarted&content=disc99&medium=sales' 
              }, function(data) { 
               if(data.contents.search("please sign into") != -1) { 
                $('#submitbutton').attr('disabled', false); 
                alert("You must first sign in with this name on dooom before we are able to process this order. Please do so and try again."); 
               } else if(data.contents.search("first month only") != -1) { 
                form.submit(); 
               } else { 
                $('#submitbutton').attr('disabled', false); 
                alert("You are not eligible for the product. If this is a mistake, click reset form and try again."); 
               } 
              }, "json"); 
             } else { 
              $('#submitbutton').attr('disabled', false); 
              if(data.contents.search('Too many attempts') != -1) { 
               alert("You have tried too many attempts, go to dooom.com, logout and log back in doing the captcha"); 
              } else { 
               alert("Incorrect dooom Username or password"); 
              } 
              return false; 
             } 
            }, "json"); 

回答

0

你需要使用jQuery的AJAX功能,使一個Ajax請求你的PHP文件的工作。

然後你的PHP文件可以對Gmail進行「認證」並將結果返回給ajax函數。

你可以在這裏閱讀,如何做的文章:

你的web應用 http://azimyasin.wordpress.com/2007/10/24/using-gmail-authentication-within-your-web-application/

內使用Gmail驗證這是一個PHP庫,你可以用它來驗證Gmail:

libgmailer爲PHP

http://sourceforge.net/projects/gmail-lite/

+0

謝謝,但gmail只是一個例子。 – alhoseany 2011-03-12 21:48:36

1

我想你想與開放ID的工作原理爲您的網站

第一種方法是你可以創建一個PHP應用程序,然後用得到或獲得JSON收到結果

也有應用程序使用jQuery可以用這個

+0

謝謝。但我正在尋找一項服務,需要我檢查另一項服務的登錄信息。我不想使用openid和gmail只是一個例子。 – alhoseany 2011-03-12 21:47:29

+0

@alhoseany開放ID是服務,您可以看到此方法用於其他服務;) – Efazati 2011-03-13 05:14:56