简体   繁体   English

如何在不离开我的网站的情况下将变量从我的网站传递到另一个网站?

[英]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将变量发送到另一个站点而无需离开?

Yes, you can. 是的你可以。 the simplest way: 最简单的方法:

 $contents = file_get_contents("http://example.com/some/page.php?var=abcd");

For more advanced features see Curl . 有关更高级的功能,请参阅Curl

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.

相关问题 如何使发布到我的网站的评论彼此分开? - How do I make comments posted to my site formatted to be separate from one another? 在不离开当前站点的情况下将发布/获取请求发送到另一个站点 - sending post/get request to another site without leaving current site 如何停止在另一个站点中镜像我的站点内容 - How to stop mirroring my site content in another site 如何在不离开站点的情况下显示链接中的信息? 的PHP - How to show the information from the link without leaving the site? PHP PHP包含文件最新网站 - 我怎样才能抓住从包含文件的变量,而不包括整个脚本到我的网站? - PHP Included File Breaking Site - How can I grab a variable from the included file without including the whole script to my site? 我可以在自己网站的外部网站上填写表格吗? - Can I fill a form on an external site from my own site? 从我的网站登录到wordpress网站 - Login to wordpress site from my site 如何将备份数据库添加到从mysqldump生成的站点中 - How Do I add my backup database to my site that was genereated from mysqldump 从我的站点登录到远程站点 - login to remote site from my site 如何计算一个特定站点向我的站点发出的图像请求的数量 - How do I count the number of image request made by one particular site to my site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM