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! (10 points for the person that finally answers this question!)
get the php page to return the value you need or set up another page whos job is to return the value you need
When you say "I call this php page using Javascript" do you mean an iframe ? Apart from that, you'll need to explain yourself a little better as to what exactly you are trying to fetch from the external site. Plus because your wanting to use .html pages, you will need to set your sever to phrase php codes on a html page, because most likely your going to have to use php either curl() or file_get_contents()
Basically what you're expecting is nothing but a standard AJAX call. Try this: The HTML Code: <html> <head> <script type="text/javascript"> function showValue(str) { var xmlhttp; if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","http://anothersite.com/show-value.php?name="+str,true); xmlhttp.send(); } </script> </head> <body> <div id="txtHint"></div> <input type="text" name="mytxt" id="mytxt" /> <input type="button" value="Find Email" onclick="javascript:showValue(document.getElementById('mytxt').value);" /> </body> </html> HTML: After entering a name in mytxt text field, when you clicks the 'Find Email' button it makes a call to show-value.php file hosted on anothersite.com (a different site) and it prints the value returned by the ajax call (in turn, the PHP file) to 'txtHint' div tag. So your PHP code looks something like this: <?php //code for DB connection //Code for executing the appropriate MySQL Query - something like [I]"select * from users where name='".$_GET['name']."' limit 1"[/I] //The resultset is stored in $data, a multi-dimensional array. while($info=mysql_fetch_array($data)){ print $info['email_id']; //remember, AJAX call returns the Printed output of the PHP file, you can't receive the return value of a function, using PHP. So, do remember to Print the value (which is expected to be returned from the PHP File) instead of returning it. } ?> Code (markup):
But "techbongo" but some one told me that "to include file just add path from file where you include example: you have: index.php a\a.php so you write in index.php include("./a/a.php"); p.s. i believe you canot include file from other domain, because many servers don't let to do so."
You asked how to include remote domain file with Javascript.... Whenever a separate call to a file on server arrives and you use Javascript to make the call from current page - it's called AJAX. You can easily use include() function to include a external file to your PHP page. But if you want to include URLs (if external domain, you have to give full URL), you need to configure that in your PHP setting of server. If you're on Shared server, probably your web host won't allow you to include URLs for security reason. In this regard have a look at following pages: http://php.net/manual/en/function.include.php http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
I checked both http://php.net/manual/en/function.include.php http://www.php.net/manual/en/filesys...llow-url-fopen And I think second is more better for my problem. Thanks for share it here.