如何使用jQuery检查远程网站的登录信息

时间:2011-03-12 07:52:09

标签: php jquery

我有一个包含2个字段的表单 用户名: 密码: 和一个提交按钮。 用户将输入他的远程网站的用户名和密码(不是我的网站或我的域名,例如Gmail.com)。 我想要一旦他点击提交按钮。一个jQuery脚本检查gmail.com上的这些登录信息并返回结果。他们是错误的或工作登录。并通知用户登录是否错误,但如果是良好的工作登录信息,表格将提交。

我不太了解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");

2 个答案:

答案 0 :(得分:1)

我认为您希望使用您网站的开放ID工作

第一种方法是你可以用php创建应用程序然后用get或get json接收结果

还有jquery的应用程序可以使用此

答案 1 :(得分:0)

您需要使用jquery ajax函数对PHP文件发出ajax请求。

然后,您的PHP文件可以“验证”Gmail并将结果返回给该ajax函数。

您可以在此处阅读“如何”文章:

在您的网络应用程序中使用Gmail身份验证 http://azimyasin.wordpress.com/2007/10/24/using-gmail-authentication-within-your-web-application/

这是一个可用于对Gmail进行身份验证的PHP库:

用于PHP的libgmailer

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