简体   繁体   English

从响应卷曲PHP获取参数

[英]getting parameter from a response curl php

I'm really newbie with php. 我真的是php新手。 I'm trying to develop a simple php app. 我正在尝试开发一个简单的PHP应用程序。 I have a button in my app and I want when I click on it to open some webpage, allow an user to connect using his credential. 我的应用程序中有一个按钮,当我单击它以打开一些网页时,我希望它允许用户使用其凭据进行连接。 When the user is connected he can grant me a privilege to access to his information by clicking in some button "Allow". 当用户连接时,他可以通过单击“允许”按钮来授予我访问其信息的特权。 After clicking in that button, he is redirected to an url that contain a parameter named "code". 单击该按钮后,他将被重定向到包含名为“ code”的参数的URL。 My goal is to use this code parameter in my php script. 我的目标是在我的PHP脚本中使用此代码参数。 I found some information about curl and I guess I need it to do that but how ? 我发现了一些有关卷曲的信息,我想我需要这样做,但是怎么做呢? I can open google webpage by doing this : 我可以这样打开google网页:

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.google.com");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
print $result;
?>

To resume I would like to know : 1) After redirecting the user to a website, after his logging and allowing me to access to his data, how can I get a parameter that is include to the url he is redirected after allowing me the access. 要恢复,我想知道:1)将用户重定向到网站之后,在他登录并允许我访问他的数据之后,如何获得一个参数,该参数包含在他允许我访问后被重定向的URL中。 Thank you in advance for your help. 预先感谢您的帮助。

You can get the URL parametrs by GET, example 您可以通过GET获得URL参数,例如

www.example.com/user?id=1111&Fname=john&Lname=Doe

...in your PHP : ... ...在您的PHP中:...

$id=$_GET['id'];
$Fname=$_GET['Fname'];
$Lname=$_GET['Lname'];

To use the CURL : 要使用CURL:

<?php
$url="yourURL?id=$id&Fname=$Fname&Lname=$Lname";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
print $result;
?>

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

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