[英]How do I pass Variables from my site to another site without leaving my site?
I would like to be able to send variables to another website without actually going to the website using php. 我希望能够将变量发送到另一个网站,而无需使用php实际访问该网站。
I am building an ecommerce website where the shipping warehouse is being outsourced. 我正在建立一个电子商务网站,其中的货运仓库正在外包。 After the person checks out with their products, I would like to send some variables over to the shipper's website using $_GET['vars']. 在该人员检查他们的产品后,我想使用$ _GET ['vars']将一些变量发送到托运人的网站。 This is a completely different URL. 这是一个完全不同的URL。 The problem is, I don't want the person actually going to the shipper's webpage. 问题是,我不希望这个人真正去托运人的网页。 I just want to ping that info over there. 我只想在那边ping那些信息。
Is is possible to send Variables via URL to another site without leaving yours? 是否可以通过URL将变量发送到另一个站点而无需离开?
You should be storing all the relevant order info within your database then using cron to trigger a script that will process the unprocessed, this way systematic checks can be made on orders before any request to your outsource site. 您应该在数据库中存储所有相关的订单信息,然后使用cron触发将处理未处理的脚本,这样就可以在对您的外包站点发出任何请求之前对订单进行系统检查。 Dont rely on your users browser to hit a curtain point in the order process to trigger the API call or trust them not to triple click or inject values before submitting. 不要依赖于您的用户浏览器在订单处理中触及一个窗帘点来触发API调用或信任他们在提交之前不要三次点击或注入值。
And I advise to use curl todo your actual request as its faster. 我建议使用curl todo你的实际请求更快。 Something as simple as: 简单的事情:
<?php
function curl_do_api($url){
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
?>
Both are right and you should make your choice based on security you're looking for. 两者都是正确的,你应该根据你正在寻找的安全性做出选择。
cURL will be more secure and you should use it if you do not want to pass some argument in query string. cURL会更安全,如果你不想在查询字符串中传递一些参数,你应该使用它。 At the same time when you pass data using file_get_cotents("URL?data=value"); 在使用file_get_cotents(“URL?data = value”)传递数据的同时; you will have limit of about 2k for data being passed. 对于传递的数据,您将有大约2k的限制。
On the other side cURL will be secure if you use it with https it's much more secure. 另一方面,如果您使用https,cURL将是安全的,它更加安全。 With cURL you will also be able to post files and emulate form post. 使用cURL,您还可以发布文件并模拟表单帖子。
actually there is a more simpler way of solving this...using ajax 实际上有一种更简单的解决方法...使用ajax
include the jquery header first 首先包含jquery标头
refer here 请参考这里
http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.ajax/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.