...

View Full Version : Php + javascript



arabab
10-14-2008, 10:13 PM
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.

snapplepitchcoc
10-14-2008, 11:18 PM
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 (http://javascript.internet.com/user-details/ip-address.html). You might want to poke around for alternatives but the linked script is a start.

arabab
10-15-2008, 12:16 AM
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).

snapplepitchcoc
10-15-2008, 03:10 AM
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?

ohgod
10-15-2008, 02:39 PM
couldn't you put the ip page in a hidden iframe, and then get the contents?

arabab
10-18-2008, 03:09 AM
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:confused: does anyone know if it would be possible to do this using another client-side language.

JygzIsHere
10-18-2008, 06:28 AM
try ajax, not sure:




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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum