首页
\
问答
\
使用PHP cURL扩展在两个网站之间共享相同的cookie(share the same cookie between two website using PHP cURL extension)
使用PHP cURL扩展在两个网站之间共享相同的cookie(share the same cookie between two website using PHP cURL extension)
我想在我的Gmail帐户中获取一些电子邮件的内容。 我想使用PHP cURL扩展来执行此操作。 我在第一次尝试时遵循了以下步骤:
- 在PHP代码中,输出https://www.google.com/accounts/ServiceLoginAuth的内容。
- 在浏览器中,用户输入用户名和密码进行登录。
- 在PHP代码中,将cookie保存在名为cookie.txt的文件中。
- 在PHP代码中,将请求发送到https://mail.google.com/以及从cookie.txt检索到的cookie并输出内容。
以下代码不起作用:
$login_url = 'https://www.google.com/accounts/ServiceLoginAuth'; $gmail_url = 'https://mail.google.com/'; $cookie_file = dirname(__FILE__) . '/cookie.txt'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_URL, $login_url); $output = curl_exec($ch); echo $output; curl_setopt($ch, CURLOPT_URL, $gmail_url); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $output = curl_exec($ch); echo $output; curl_close($ch);
I want to get the contents of some emails in my gmail account. I would like to use the PHP cURL extension to do this. I followed these steps in my first try:
- In the PHP code, output the contents of https://www.google.com/accounts/ServiceLoginAuth.
- In the browser, the user input username and password to login.
- In the PHP code, save cookies in a file named cookie.txt.
- In the PHP code, send request to https://mail.google.com/ along with cookies retrieved from cookie.txt and output the contents.
The following code does not work:
$login_url = 'https://www.google.com/accounts/ServiceLoginAuth'; $gmail_url = 'https://mail.google.com/'; $cookie_file = dirname(__FILE__) . '/cookie.txt'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_URL, $login_url); $output = curl_exec($ch); echo $output; curl_setopt($ch, CURLOPT_URL, $gmail_url); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $output = curl_exec($ch); echo $output; curl_close($ch);
原文:https://stackoverflow.com/questions/2845684
更新时间:2023-07-19 18:07
最满意答案
您可以尝试使用:
Math.round(yournum * 1000) / 1000
或者你可以尝试:
+(Math.round(num + "e+3") + "e-3")
You can try to use:
Math.round(yournum * 1000) / 1000
or you can try:
+(Math.round(num + "e+3") + "e-3")
相关问答
更多-
好的,好问题! var price = 0 $('.unit_price_d').each(function(){ price_d = parseFloat($(this).text()).toFixed(2); //span console.log(price_d); $(this).text(price_d) }) 注意两件事。 使用*.each()*和*this*关键字迭代,代码开启! ok, good question! var price = 0 $('.unit_pr ...
-
toFixed不是非数字变量类型的方法。 换句话说, Low和High不能被修复,因为当你在Javascript中获得某些东西时,它会自动设置为一个字符串类型。 使用parseFloat() (或parseInt()与radix,如果它是一个整数)将允许您将不同的变量类型转换为数字,这将使toFixed()函数工作。 var Low = parseFloat($SliderValFrom.val()), High = parseFloat($SliderValTo.val()); toFixed ...
-
这将返回预期的输出: function add(){ // Initialize output and "length" properties var length = 0; var output = 0; // Loop through all arguments supplied to this function (So: 1,4,6 in case of add(1,4,6);) for(var i = 0; i < arguments.length; i++) ...
-
...最好不解析和操纵.toFixed(2)出来的字符串? 好吧,你可以用数字来做,尽管我担心在数字逻辑和固定的逻辑之间取得完美的匹配,因为toFixed的定义包括以下短语: 设n是n ÷10 f - x的精确数学值尽可能接近零的整数。 如果有两个这样的n ,选择较大的n 。 所以我可能只是更新字符串,这不是很多工作: function formatNumber(num) { return num.toFixed(2).replace(/\.00$/, ""); } function te ...
-
您必须将选项的值除以100 ,如: http : //jsfiddle.net/csdtesting/14rh32ou/ $("#amount").change(function () { var amount = parseInt($("#amount option:selected").val()) / 100; var amount = amount.toFixed(2) $(".amountShow").text('$' + amount); }); You have t ...
-
您可以尝试使用: Math.round(yournum * 1000) / 1000 或者你可以尝试: +(Math.round(num + "e+3") + "e-3") You can try to use: Math.round(yournum * 1000) / 1000 or you can try: +(Math.round(num + "e+3") + "e-3")
-
我不确定你为什么在你的区块中有alert('bad') ; 所有真正发生在“坏”情况下的是, number变量已经有一个名为toFixed的成员定义(当强制转换为布尔值时,它的结果为true - 对于函数来说总是如此)。 这不一定是坏事,因为这是你想要的最终结果?! 如果没有本机*实现,代码似乎是定义了一个版本toFixed 。 当有本机*支持时,警报会触发。 *(好吧,无论是浏览器原生还是已经由JS库添加到原型中。无论哪种方式,它已经存在,因此不再需要工作。) I'm not sure why you h ...
-
var amount = +"100"; $('#subpaymentbalance').val(amount.toFixed(2)); 如果response.feestudent_amount是字符串,则需要执行此操作。 需要在Numbe ...
-
javascript toFixed()(javascript toFixed())[2023-06-30]
我建议你使用一个库: https://github.com/MikeMcl/decimal.js 在使用金融数据时,我发现它非常可靠。 使用浮点数总是很困难,但有几种解决方案。 我建议你使用一个维护得很好的existsin库,这个库已经被淘汰了。 假设您添加了decimal.js,您可以为财务值执行此操作。 /** * @var input float */ function toFixed(input) { var dec = new Decimal(input); return d ... -
将代码更改为使用toFixed,如下所示。 thePercent.text( (100 * fnumber).toFixed(2) ); 您想先执行计算,然后将其发送到toFixed()方法 Change your code to use toFixed like this. thePercent.text( (100 * fnumber).toFixed(2) ); You want to perform the calculation first then send it to the toFixe ...