感謝stackoverflow我得到了我的小項目,但我需要一些建議了。我想檢查用戶是否登錄了domain1.com並在domain2上返回消息。代碼還有很多。下面我列舉了一個基本的例子。在http://domain2.com檢查用戶是否從不同的域登錄
<script type="text/javascript" src="http://domain1.com/test.php?js"></script>
test.php的
的index.php是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在http://domain1.com。這是我想要檢查用戶是否登錄的位置。如果用戶登錄,文件被寫入,如果沒有,我想發送消息到domain2.com要求登錄。
<?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");
這最後一部分我從上一個問題得到。 <?php echo $callback; ?>("Message from the server");
如果這是domain2的消息,我該如何調用它?
感謝。你能告訴我一切順利?我一直很努力,但不能讓它開始工作。 – Ciprian 2011-12-17 16:55:32