Hi, I'm trying to get some result from a remote php page so what I was planning to do is to have a page A with the code: <script xxxxx B.php></script> This way I can print something taken from page B. I was thinking if there is an easy way to do that. Maybe I should use javascript too? Thanks (I hope it's clear what I meant) ps. don't say use include because I can't do that. especially if it's on a remote server and it sends cookies.
A simple AJAX script maybe? <script type="text/javascript> function GetXmlHttpObject() // Returns xmlHttp object { var obj; var xmlHttp = null; try { // Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function AjaxGet(element, str, remote) // Pass element id, string, and remote page { obj = document.getElementById(element); if (str.length == 0) { obj.innerHTML=""; return; } xmlHttp=GetXmlHttpObject() if (xmlHttp == null) { alert ("Your browser does not support AJAX!"); return; } var url = remote; url = url + "?q=" + str; url = url + "&sid=" + Math.random(); xmlHttp.onreadystatechange = stateChanged; xmlHttp.open("GET", url, true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState==4) { obj.innerHTML=xmlHttp.responseText; } } </script> Code (markup): Define a div (let's say it has id="bstuff") to hold the stuff you want from page B. Then call AjaxGet('bstuff', querystring, 'b.php'); The querystring is a string that gets appended to the URL (the page will automatically be called as b.php?q=querystring -- just put in a dummy value for q if you don't use it and add your querystring to the end of it). Once the function is called (by an event handler, I assume), then presto-change-o, your previously empty div with id="bstuff" magically contains whatever b.php spit out. May not be exactly what you're looking for, but it has worked well for me in similar situations.
I will check it. But I'm not sure it's the right thing, and probably is too "heavy".. It should be somethink like an Adsense page. I haven't used one yet, but I think they do the same thing I want to do and they surely doesn't ask you to curl or to add a piece of ajax/javascript.
It seems that my problem is more serious.. I have a file a.php <?php echo "a</br>"; ?> <script type="text/javascript" src="bbb.php"></script> b and a file bbb.php with: <?php echo "hello world"; ?> and all I see is a b and a lovely error on FF javascript console telling me that I should add a ; before "world" on the second file. ??? What am I missing here??
File bbb.php needs to echo some valid JavaScript - "hello world" is not valid JavaScript... You can try something like this in bbb.php: <?php echo "alert('Hello World');"; ?> PHP:
Thanks, you are right. Then how can I print something on the screen? If I have <td><script....</td> I want that my script fills that place. Is it possible or I have to do <td><div class="iknowu"><script...></div></td> and then write a script that change the value of the "iknowu" object? (this is maybe a JavaScript question, rather than a php one..sry)
Were you looking for something like this? page A <?php echo "Today's message is: <b>".file_get_contents ('http://someplace/pageb.php').'</b>'; ?> PHP: page B <?php $messages = array (); $messages[] = 'Hi there'; $messages[] = 'Whats up?'; $messages[] = 'How are you'; $messages[] = 'Good day to ya'; echo $messages[array_rand ($messages)]; ?> PHP:
Good idea, but the answer is no. The reason is simple (but stupid me, I forgot to tell) The page B, wich is the page that calls the script, *could* be a simple html page, an asp, wap page, whatever... I probably have to put <div as I said..
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooh document.write! I think I need to buy a book about Javascript sooner or later.. Thanks a lot! I will try it! we need a /bow smiley