1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How do I use php code from a different domain?

Discussion in 'Programming' started by Rumon BD, Aug 31, 2012.

  1. #1
    Here's what I'm trying to do: I have a php page I created on one domain, that stores information in a database. Next, I have another web page (This page is html NOT php) on a Different domain that I call this php page using Javascript, and would like to return a variable from the php page. How is this possible? I know it is, so don't say that it isn't!
     
    Rumon BD, Aug 31, 2012 IP
  2. hassanahmad2

    hassanahmad2 Active Member

    Messages:
    243
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You cannot access a webpage (PHP or anything) residing on a different domain using Javascript. It's known as the same origin policy.
     
    hassanahmad2, Aug 31, 2012 IP
  3. bar.developer

    bar.developer Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    How do you call the PHP page?
    And you said that you succeeded to call the PHP page, so what is the problem?
     
    bar.developer, Sep 1, 2012 IP
  4. formicin

    formicin Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    When you try to embed another PHP, it should be on the same server. Otherwise it will embed the output.
     
    formicin, Sep 12, 2012 IP
  5. xuled

    xuled Banned

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can not export scripts from a different server. This is actually can not be done with this, as far as i know. I think you better should consult it with someone expert.
     
    xuled, Sep 16, 2012 IP
  6. WeddiGo

    WeddiGo Greenhorn

    Messages:
    40
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    18
    #6
    Simple, you have to use AJAX...I do it all the time. Here is a brief explanation how it works.1. Create a servers side page (php, asp etc...) that does something clever like getting stuff from a database. The output of that page should be pure text, for example the page should just printout the variable value that you've mentioned without any html formating. In ASP you would use response.write() (not sure what it is in php)[br]2. In the html page that resides on a different server use an AJAX call in JavaScript to the page above[br]3. In the same Javascript capture the return value (that will be the text output I've mentioned in step 1)[br]4. do something in javascript with that valueNow...what is AJAX, well it's simply a XMLHttpRequest...if you can't be bothered coding a full XMLHttpRequest procedure you can use jQuery which can reduce the amount of coding on your side drastically...here's a simplejQuery example:
    function getRemoteValue{  var someValue = 100 //this is just to show that you can send variables to your remote page      $.post("http://www.myremoteserver.com/getvalues.php", {ID: someValue }, //we rae using POST here, just like submitting a form        function(data){   //data is the returned text content of your database page after the AJAX has finished              setDefaults(data);    // call another function that can deal with the data      });
    Code (markup):
    Hope this helps
     
    Last edited: Sep 21, 2012
    WeddiGo, Sep 21, 2012 IP
  7. tkcoding

    tkcoding Peon

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If what you mean is to call some PHP function from another domain and retrieve the output than yes, you can make ajax request using javascript.

    but, if what you mean is to retrieve php script from another domain, than it is absolutely no, we just can't do that thing
     
    tkcoding, Sep 29, 2012 IP