Thread: cURL in PHP

    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    579
    Rep Power
    51

    cURL in PHP


    I have successfully used cURL to display PHP/MySQL reports from one domain on a web page on an entireIy different domain... works fine.

    Now, I am trying to include an order form from one domain on a web page on a different domain. The "guts" of the order form is a file called "web_store_core.php" on domain1, where the data resides. The order form on domain2 is a simple shell page with the following cURL commands:

    PHP Code:
    <?php
    $URL
    ="domain1/web_store_core.php?cust_id=7";
    $ch curl_init();
    curl_setopt ($chCURLOPT_URL"$URL");
    curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
    curl_setopt ($chCURLOPT_FOLLOWLOCATION1);
    $contents curl_exec($ch);
    curl_close($ch);
    // display file
    echo $contents;
    ?>
    As you would expect, the form in web_store_core.php is submitted when the order is placed. The problem is that when the form is submitted, the browser is looking for web_store_core.php on the calling domain (domain2) and not finding it.

    The <form> statement in is as follows:
    PHP Code:
    <form method=\"post\" action=\"$_SERVER[PHP_SELF]\"> 
    Is there a way that I can use cURL to make sure the form processing stays on Domain1 and does not look for it back on Domain2?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,472
    Rep Power
    653
    You would need to create a 'web_store_core.php' on domain 2 then use curl there to pass the appropriate data back to domain1. The action value is pointing to the server that the browser thinks is the source.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,904
    Rep Power
    9646
    Should I mention that this whole "cURL the page from another domain" solution is entirely the wrong way to go about whatever it is you need to do?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    579
    Rep Power
    51
    Originally Posted by requinix
    Should I mention that this whole "cURL the page from another domain" solution is entirely the wrong way to go about whatever it is you need to do?
    Thanks... After reading your response, I was pretty much assuming that. So... what I want to do is:

    1. I have a business management tool written in PHP/MySQL/Javascript that my customers use to manage their businesses.
    2. Each of my customers has a unique login and proprietary data.
    3. Their customers, in turn, can login to the system through a "portal" to interact with data that is pertinent to them.
    4. This portal includes a "portal store" where my customer's can sell items to their customers.
    5. All of this resides on one server, one domain.

    Now, I would like to be able to extend the notion of the "portal store" to a "web store", where my customers can offer items for sale to the general public. Since the general public would not have access to the "portal" on my domain, this would necessitate my customers adding a store to their own web sites, therefore a different domain.

    So, I was hoping that I could include "order forms" that reside on my domain on a page that resides on my customer's web page, a different domain, and the order forms would be processed in the context of the database on my domain. I thought cURL might be a way to do that..

    I actually tried the old "<Iframe>" method and to my surprise that actually worked (to a point).

    Can you point me to a better method?

    Thanks again.
  8. #5
  9. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,904
    Rep Power
    9646
    An iframe would actually be the better solution, but the best solution would be to have your site offer a way to sell to the general public. Etsy and eBay don't make their sellers use their own websites...

    If you just want something like an order form, so not really much beyond the form to place the order for whatever item, then there are a few options. What you need to do to start is to come up with specific requirements that you can meet: what needs to be supported, what your customers can do with their own domain, how the end-user interacts with the customer and your order process, etc.

IMN logo majestic logo threadwatch logo seochat tools logo