0

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");
3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Stefano Mtangoo
0

I'm no expert, but I think this is what you're trying to do:

- Execute a script on "domain1.com" that checks if the user is logged in
- Stores the result in JSON

- On "domain2.com" have a script that reads the JSON and then checks whether someone is signed in

Is this correct?

0

Yeah ... but I m just not sure how to send the information.

0

Okay.. This is how I would do it..

1. Check to see if the user is online

2. Store it using JSON which would output something like this:

{"user1":"true","user2":"false"}
// user1 is signed in, user2 isn't

3. Then use something like curl to get this information
www.domain1.com/checkUser.php?key=20420420
(The key for security)

4. Decode the json and then do whatever you want on the variable.

Does this make sense, or, have I just confused you even more?

I don't see why you're storing the values in a .txt file!

0

Yeah a bit. :) I m storing it in a txt file just for testing. It will go to a db. There's more to the code. Would it be too much to ask for you to write a small example? This is still a bit confusing, but I'll understand the code if I see it.
Thank you very much for your help.

Edited by cip6791: n/a

0

Use AJAX Calls from one domain to another. If they share database then just check isOnline field which you must set in that other domain!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.