单击按钮自动登录另一个网站 - cURL 还是 Javascript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7999613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:57:25  来源:igfitidea点击:

Automatically log in on another website at the click of a button - cURL or Javascript?

phpjavascriptjquerycurl

提问by

I would like to make a button on my website that automatically logs me in on another website. I recon I can use either Javascript/jQuery or PHP/cURL to do this.

我想在我的网站上制作一个按钮,让我自动登录另一个网站。我认为我可以使用 Javascript/jQuery 或 PHP/cURL 来做到这一点。

Which is the best way to go?

最好的方法是什么?

采纳答案by Shattuck

I'm not sure if this is exactly what you're looking for, but one thing I have done in the past is to mimic the login form on the site you want to log in to. For example lets say you want to log in to 'example.com'. In the source code for the login page of 'example.com' you will find the html code for the login form.

我不确定这是否正是您要查找的内容,但我过去做过的一件事是模仿您要登录的站点上的登录表单。例如,假设您要登录“example.com”。在“example.com”登录页面的源代码中,您将找到登录表单的 html 代码。

Example

例子

<form name="blabla" action="action.php" method="post">
    <input type="text" name="username" />
    <input type="password" name="password" />
    <input type="sumbit" value="Login" />
</form>

Create a form on your site similar to the one you find in 'example.com'. If you want you can even hide the fields, include values to make it a one button login. The trick is making sure that the action has the actual url. For example if the form says 'action.php' for 'example.com' you would put 'http://example.com/action.php'

在您的网站上创建一个类似于您在“example.com”中找到的表单。如果您愿意,您甚至可以隐藏字段,包括值以使其成为一键登录。诀窍是确保操作具有实际的 url。例如,如果表单为“example.com”显示“action.php”,您将输入“http://example.com/action.php”

Example

例子

<form name="blabla" action="http://example.com/action.php" method="post">
    <input type="hidden" name="username" value="testuser" />
    <input type="hidden" name="password" value="testpass" />
    <input type="sumbit" value="Login" />
<form>

This will log you in to the site in most cases. If you don't want to leave your own site you can set a 'target' for the form to an iframe or something.

在大多数情况下,这将使您登录到该站点。如果您不想离开自己的网站,您可以将表单的“目标”设置为 iframe 或其他内容。

回答by Pavel Podlipensky

You may use either remote javascript or iFrame. Find more details here: http://kuza55.blogspot.com/2007/06/building-secure-single-sign-on-systems.html

您可以使用远程 javascript 或 iFrame。在此处查找更多详细信息:http: //kuza55.blogspot.com/2007/06/building-secure-single-sign-on-systems.html

Also checkout google's approach named SAML: http://code.google.com/googleapps/domain/sso/saml_reference_implementation.html

还要检查谷歌名为 SAML 的方法:http: //code.google.com/googleapps/domain/sso/saml_reference_implementation.html

回答by BenM

It depends what the website is. JavaScript and jQuery alone cannot be used due to the cross-domain policy. You could perhaps use a combination of cURL and AJAX to achieve something similar.

这取决于网站是什么。由于跨域策略,不能单独使用 JavaScript 和 jQuery。您也许可以使用 cURL 和 AJAX 的组合来实现类似的功能。

I think you might need to provide a little more information about the site, and exactly why you'd want to do this...

我认为您可能需要提供有关该网站的更多信息,以及您为什么要这样做...