简体   繁体   English

用php curl登录instagram

[英]login instagram with php curl

I want to login this page with php: But I get error when I try to login with php. 我想使用php登录此页面 :但是当我尝试使用php登录时出现错误。

When I try to login below code is always changing. 当我尝试登录以下代码时,代码总是在变化。 So I cannot login. 所以我无法登录。

The code is: 代码是:

 <input type="hidden" name="csrfmiddlewaretoken" value="728a44ea6f15dee51406b0c82be3a03b"/>

Thanks for advance help 感谢您的提前帮助

Obviously Instagram is protected against cross-site request forgery. 显然,Instagram可以防止跨站点请求伪造。 You can read all about this attack here . 您可以在此处阅读有关此攻击的所有信息。

Actually the Instagram guys do not want you to submit the login form without showing it first. 实际上,Instagram人士不希望您先提交登录表单而不先显示它。 That is what csrfmiddlewaretoken is for: They give it to you (random value) when the form is displayed and when you submit it, they check whether you returned the one they gave you. 这就是csrfmiddlewaretoken的用途:当显示表单时,他们将其提供给您(随机值),当您提交表单时,他们将检查您是否返回了给您的表单。 See the OWASP cross-site request forgery prevention cheat sheet . 请参阅OWASP跨站点请求防止伪造备忘单

So basically what you have to do is request the login form, get the token from it and then log in in a second request and include that token in it. 因此,基本上,您要做的是请求登录表单,从中获取令牌,然后登录第二个请求,并将该令牌包含在其中。

(Maybe they do some double checking there; in this case you'll have to send the token twice: both in your post data and as a cookie.) (也许他们在那里做了一些仔细的检查;在这种情况下,您将不得不两次发送令牌:在您的帖子数据中和作为cookie。)

You must open the page with the form and read the value of "csrfmiddlewaretoken" into a var (with a regex for example). 您必须使用表单打开页面,并将“ csrfmiddlewaretoken”的值读入var(例如,使用正则表达式)。

You also have to store the session cookie (curl has a method for storing cookies in a container file, or you can do it yourself by parsing the answer headers and storing the cookie value to set it in you request header for later requests). 您还必须存储会话cookie(curl提供了一种将cookie存储在容器文件中的方法,或者您可以通过解析答案标头并存储cookie值以将其设置在请求标头中以用于以后的请求来自己进行操作)。

Then you can set the "csrfmiddlewaretoken" in your login request (which needs to send the session cookie). 然后,您可以在登录请求中设置“ csrfmiddlewaretoken”(需要发送会话cookie)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM