在等待来自其他站点的值时显示或隐藏div元素

In PHP, is it possible to use conditions that will display either one of two div elements? My pseudocode:

//in Site 1
$tokenFromSite1 = 'xxx';
$tokenFromSite2 = '';
while($tokenFromSite1 != $tokenFromSite2){
    //show div containing Connect button;
    clickConnect(); //includes $tokenFromSite1 value as URL param "token" and opens a new tab to Site 2
        //in Site 2
        //gets $tokenFromSite1 value and opens a URL containing this value as param "token" and redirects to site 1
    //back to Site 1
    $tokenFromSite2 = //GET value of param "token"
}
//div containing Connect button disappears and shows a div that says "Connected"

I am not sure if my logic is correct, and how exactly is Site 1 going to "wait" for the token value from Site 2. Also, how do I hide/show div elements?

It's not possible. PHP is compiled server side. It will run the full script and then output the results. In order to achieve what you want you will need a jQuery code that uses AJAX. Because it's a client side script it can interact with the user's screen after the page is loaded.