PHP脚本执行多个URL?
是否有一种 php 脚本可以运行一系列 URL,然后将用户引导到最终目的地? 它的用途是: 在没有强大的“愿望清单”功能的网站上创建结帐购物车。
该脚本运行一系列“将商品添加到购物车”网址,然后最终目的地将用户带到我为他们挑选的产品购物车。
Is there a sort of php script which will run a series of URLs and then direct the user to the final destination? the use of this is:
creating a checkout cart on a site that doesn't have a robust "wishlist" feature.
The script runs a series of "add item to cart" urls, and then the final destination takes the user to their cart of products i've picked out for them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,你可以使用 ajax 来做到这一点。
使用 jQuery 执行 ajax 请求。
例如,
如果您使用会话,那么它将被添加到当前会话中,前提是它位于同一域中。
Yes you can do this with ajax.
Use jQuery to do your ajax requests.
e.g
If you use sessions then it will be added to the current session providing it is on the same domain.
请参阅 http://php.net/curl
编辑: 至于管理远程会话通过 cURL,这取决于远程站点如何跟踪会话。 有些使用 cookie(cURL 支持),有些会生成一个 sessionid 令牌,您必须在后续请求中将其作为参数或在 http 标头中传回。
PHP 的 cURL API 的文档非常稀疏,因此您可能需要寻找更完整的教程。 我通过谷歌搜索“curl cookie教程”找到了以下内容:
http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/
See http://php.net/curl
edit: As for managing remote sessions through cURL, it depends how the remote site tracks sessions. Some use cookies (which cURL supports), some generate a sessionid token that you have to pass back in subsequent requests, either as a parameter or in the http header.
The docs for PHP's cURL API are pretty sparse, so you may have to hunt for more complete tutorials. I found the following by Googling for "curl cookie tutorial":
http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/
这实际上取决于您网站的具体情况。
如果是oo的话,也许可以依次调用相关方法将商品添加到购物篮中? 或者你可以通过包含来做到这一点?
或者该网站可能有一些您可以使用的包含文件?
或者它可能有一个机制,可以在将商品添加到购物篮后重定向用户,您可以利用它?
或者如果没有,在我写作时出现的其他答案建议了使用 javascript 或curl 实现此目的的有效方法。
it really depends on specifics of your site.
if its oo, you may be able to call the relevant methods one after the other to add items to the basket? or you may be able to do this with includes?
or it may be that the site has some include files you can use?
or it may have a mechanism to redirect users after adding items to the basket that you can take advantage of?
or if not, there's other answers that have appeared whilst i was writing that suggest valid ways to achieve this with javascript or curl.
好的,我将尝试 ajax 建议,但我不确定代码如何使用 get 和 post 进行格式化。 这就是我开始的,它不获取 url(我换成通用 url 进行演示);
ok i'm going to try the ajax suggestion but i'm not sure how the code is formatted with get and post. this is what i've started and it doesn't fetch the url(i swapped in generic urls for demonstration);