-2

I have made a site where user login with google,where a popup window opens for login,when user click the submit button,the popup window close & user redirect to another page.

I have done the code but it works fine in FF bt not working in chrome

This is my code,can anyone plz suggest what changes I need to do so that it works in chrome also.

 <?php
   @session_start();
   require 'openid.php';
   try {


$openid = new LightOpenID;
if(!$openid->mode) {

    if(isset($_GET['login'])) {

        $openid->identity = 'https://www.google.com/accounts/o8/id';
        $openid->required = array('namePerson/first', 'namePerson/last', 'contact/email');
       // @header('Location: ' . $openid->authUrl());
    echo "<script>location.href='".$openid->authUrl()."'</script>";
    }

} elseif($openid->mode == 'cancel') {
    echo 'User has canceled authentication!';
} else {
    if($openid->validate())
    {           
         'User <b>' . $openid->identity . '</b> has logged in.<br>';

         "<h3>User information</h3>";
        $_SESSION['identity'] = $openid->identity;
        $identity = $openid->identity;
        $attributes = $openid->getAttributes();
        $_SESSION['email'] = $attributes['contact/email'];
        $_SESSION['first_name'] = $attributes['namePerson/first'];
        $_SESSION['last_name'] = $attributes['namePerson/last'];


        /* "mode: " . $openid->mode . "<br>";
         "identity: " . $identity . "<br>";
         "email: " . $email . "<br>";
        "first_name: " . $first_name . "<br>";
         "last_name: " . $last_name . "<br>";*/


    }
    else
    {
        echo 'User ' . $openid->identity . 'has not logged in.';
    }


    echo "<script>window.close();</script>";
    echo '<script>window.opener.location.href="index2.php"</script>';



 }
    } catch(ErrorException $e) {
     echo $e->getMessage();
}
?> 
Suraj Shrestha
  • 1,790
  • 1
  • 25
  • 51

2 Answers2

1

i believe window.close() is not working in chrome for you. Once i faced the problem i fixed the problem using

replace window.close(); with the code below

window.open('', '_self', ''); //simple bug fix
window.close();

Also try putting the this

echo '<script>window.opener.location.href="index2.php"</script>';
echo "<script>window.open('', '_self', '');window.close();</script>";

Hope it works for you too.

if not please be more specific about the question

  • You don't need two echo lines/script blocks for that. – rekire Feb 27 '13 at 06:11
  • I have used this which works fine in FF and chrome but not working in IE that means not redirecting to index2.php .Is there any way to do in IE also. – priti upadhyay Feb 28 '13 at 12:05
  • opener dont work in IE , try the alternatives here [Window Opener Alternatives](http://stackoverflow.com/questions/4885765/window-opener-alternatives) – Abhishek Shaw Mar 05 '13 at 06:46
0

Please try with below any one of the option

echo('opener.window.location.reload(true); window.close();'); or echo('window.opener.location.reload(false); window.close();');

if still problem exist let me know

kapil
  • 162
  • 5