PHP script execute multiple urls?

Is there some PHP script that will run a series of URLs and then direct the user to their final destination? using this: creating a shopping cart on the site that does not have a robust "wish list" feature.

The script runs a series of "add item to cart" urls and then the final destination sends the user to their cart of the products I have selected for them.

+1


source to share


4 answers


Yes you can do it with ajax.

Use jQuery to complete your ajax requests.

eg



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

      

If you are using sessions, it will be added to the current session if it is on the same domain.

+6


source


See http://php.net/curl

edit: As far as managing remote sessions via cURL, it depends on how the remote site is tracking sessions. Some use cookies (which cURL supports), some generate a sessionid token that you need to pass back in subsequent requests, either as a parameter or in the http header.



The docs for the PHP cURL API are quite sparse, so you might have to look for more complete tutorials. I found the following in Googling for the "curl cookie tutorial":

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

+3


source


it really depends on the specifics of your site.

if its oo, can you call the appropriate methods one by one to add items to the cart? or can you do it with?

or it might be that the site has some included files that you can use?

or it might have a mechanism to redirect users after adding items to the cart that you can use?

or, if not, there are other answers that came up at the time of writing that suggest correct ways to achieve this with javascript or curl.

0


source


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 started and it doesn't fetch url (i changed common urls for demo);

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

      

0


source







All Articles