Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Php + javascript

    hi guys i don't know if this can actually be done using javascript (since i'm virtually js illiterate) but i'll give it a try anyway. i have a php page on a sever that supports it. opening this page will give you your ip address without any html or anything. the only thing printed on the page (and in the source code) is a number. now i have a second page on a different server that doesn't support php (or any other server side programming language). i want to use javascript on this second page to access the first page, get the number and print it on the 2nd page. at least sounds pretty simple. any help would be appreciated. thanks.

  • #2
    New Coder
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I assume Page 1 and 2 belong to different domains.

    In this situation, my experience is that you have to use cURL to "import" data from Page 1 to Page 2. cURL won't help you though since you say Page 2 does not have a server side scripting.

    I think you are in a tough spot. Maybe try using javascript to get the user's IP address to show on Page 2 if that's what you're tyring to accomplish? See, e.g., this. You might want to poke around for alternatives but the linked script is a start.

  • #3
    New Coder
    Join Date
    May 2007
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for the reply but this won't work since it needs sever side programming. my ip is already in the js code when i open the page (just check the source code).

  • #4
    New Coder
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Sorry; I don't understand why you can't use js to grab users' IP addresses. Why does the IP address have to come from Page 2?

    I guess I don't understand the purpose of this exercise. What is the bigger picture?

  • #5
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    couldn't you put the ip page in a hidden iframe, and then get the contents?

  • #6
    New Coder
    Join Date
    May 2007
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ohgod View Post
    couldn't you put the ip page in a hidden iframe, and then get the contents?
    yeah but then i wouldn't be able to manipulate it as a variable I am really surprised that such a simple thing cannot be done does anyone know if it would be possible to do this using another client-side language.

  • #7
    New Coder
    Join Date
    May 2005
    Location
    Cebu, Philippines
    Posts
    46
    Thanks
    1
    Thanked 10 Times in 10 Posts
    try ajax, not sure:

    Code:
    <script type="text/javascript">
    function displayContent()
    {
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
      xmlHttp.onreadystatechange=function()
        {
        if(xmlHttp.readyState==4)
          {
    	document.write(xmlHttp.responseText);
          }
        }
    
      xmlHttp.open("GET","http://www.PageOne.com/Page1.html",true);
    
      xmlHttp.send(null);
      }
    
      displayContent();
    
    </script>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •