PHP脚本执行多个URL?

时间:2022-06-03 04:49:50

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.

是否有一种PHP脚本将运行一系列URL,然后将用户引导到最终目的地?使用方法是:在没有强大“愿望清单”功能的网站上创建结帐购物车。

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.

该脚本运行一系列“添加项目到购物车”网址,然后最终目的地将用户带到他们为他们挑选的产品购物车中。

4 个解决方案

#1


6  

Yes you can do this with ajax.

是的,你可以用ajax做到这一点。

Use jQuery to do your ajax requests.

使用jQuery来执行你的ajax请求。

e.g

$.get("http://mywebsite.com/json/cart_add.php?pid=25");
$.get("http://mywebsite.com/json/cart_add.php?pid=27");

If you use sessions then it will be added to the current session providing it is on the same domain.

如果您使用会话,则会将其添加到当前会话中,前提是它位于同一个域中。

#2


3  

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.

编辑:对于通过cURL管理远程会话,它取决于远程站点如何跟踪会话。有些使用cookie(cURL支持),有些会生成一个sessionid标记,您必须在后续请求中将其作为参数或http标头传回。

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":

PHP的cURL API的文档非常稀疏,因此您可能需要寻找更完整的教程。我通过Google搜索找到了以下“curl cookie tutorial”:

http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/

#3


0  

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?

如果它是oo,您可以一个接一个地调用相关方法将项目添加到购物篮中?或者您可以使用包含这样做?

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.

或者如果没有,在我写作时会出现其他答案,这些答案建议使用javascript或curl实现这一目标的有效方法。

#4


0  

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);

好吧,我将尝试ajax建议,但我不知道如何使用get和post格式化代码。这是我开始的,它不会获取网址(我换了通用网址进行演示);

 <html>   
 <head>                                        
 <script type="text/javascript" src="jquery-1.2.6.min.js"></script>          
 <script type="text/javascript">      
 $(document).ready(function() {    
 $("a").click(function(){    
 $.get("http://www.store.com/item4");    
 $.get("http://www.store.com/item5");
 alert("Items Added, Now Redirecting");           
 });    
 });                                                         
 </script>                                                         
 </head>  
 <body>
 <a href="">Link</a>                                                                                               
 </body>                                                                        
 </html>

#1


6  

Yes you can do this with ajax.

是的,你可以用ajax做到这一点。

Use jQuery to do your ajax requests.

使用jQuery来执行你的ajax请求。

e.g

$.get("http://mywebsite.com/json/cart_add.php?pid=25");
$.get("http://mywebsite.com/json/cart_add.php?pid=27");

If you use sessions then it will be added to the current session providing it is on the same domain.

如果您使用会话,则会将其添加到当前会话中,前提是它位于同一个域中。

#2


3  

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.

编辑:对于通过cURL管理远程会话,它取决于远程站点如何跟踪会话。有些使用cookie(cURL支持),有些会生成一个sessionid标记,您必须在后续请求中将其作为参数或http标头传回。

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":

PHP的cURL API的文档非常稀疏,因此您可能需要寻找更完整的教程。我通过Google搜索找到了以下“curl cookie tutorial”:

http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/

#3


0  

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?

如果它是oo,您可以一个接一个地调用相关方法将项目添加到购物篮中?或者您可以使用包含这样做?

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.

或者如果没有,在我写作时会出现其他答案,这些答案建议使用javascript或curl实现这一目标的有效方法。

#4


0  

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);

好吧,我将尝试ajax建议,但我不知道如何使用get和post格式化代码。这是我开始的,它不会获取网址(我换了通用网址进行演示);

 <html>   
 <head>                                        
 <script type="text/javascript" src="jquery-1.2.6.min.js"></script>          
 <script type="text/javascript">      
 $(document).ready(function() {    
 $("a").click(function(){    
 $.get("http://www.store.com/item4");    
 $.get("http://www.store.com/item5");
 alert("Items Added, Now Redirecting");           
 });    
 });                                                         
 </script>                                                         
 </head>  
 <body>
 <a href="">Link</a>                                                                                               
 </body>                                                                        
 </html>