I would like to check if a user is logged on domain1.com and return a message on domain2. There is a lot more to the code, I only added a basic sample.
index.php on http://domain2.com
<script type="text/javascript" src="http://domain1.com/test.php?js"></script>
test.php is on http://domain1.com.
<?php
if (isset($_GET['js'])){
header("Content-type:text/javascript");
?>
function doAjax(){
$.getJSON("http://domain1.com/index.php/home/callback.php?name=name&callback=?",
function(message) {
alert("Data Saved");
});
}
document.write('<button onclick="doAjax();">Submit</button>');
<?php } ?>
<?php exit; } ?>
callback.php is on http://domain1.com. This is where I would like to check if the user is logged in or not. If the user is logged in, the file gets written, if not I want to send a message to domain2.com asking for login.
<?php
$callback = $_GET['callback'];
$name = $_GET['name'];
$myFile = "txt/tester.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $name);
fclose($fh);
header("Content-Type: application/javascript");
?>
<?php echo $callback; ?>("Message from the server");
If the below code is the message to domain2, how do I send it?
<?php echo $callback; ?>("Message from the server");