duankange2433 2017-07-27 08:42
浏览 118

如何使用Google+登录信息

I managed to get the user information using Google+ login.

    if (isset($authUrl)) {       
    echo "<a href='" . $authUrl . "'><img src='img/google.png'></a>";
} else {
    print "ID: {$id} <br>";
    print "Name: {$name} <br>";
    print "Email: {$email } <br>";
    print "Image : {$profile_image_url} <br>";
    print "Cover  :{$cover_image_url} <br>";
    print "Url: {$profile_url} <br><br>";
    echo "<a class='logout' href='?logout'><button>Logout</button></a>";
}

This is in a login.php file where the user logs in. How can I pass this data to the header.php so I can remove the Login and Register buttons and add the user name and image?

  • 写回答

1条回答 默认 最新

  • doushi1912 2017-07-27 09:06
    关注

    To pass info via GET:

    For redirecting in php, you use header('Location:file_name')

    header('Location: header.php?var1=val1&var2=val2');
    

    Session:

    // index.php
    session_start(); //start session
    $_SESSION['varName'] = 'varVal'; //make a session variable
    header('Location: header.php'); // redirect to header.php
    
    // header.php
    session_start(); //start session
    $myVar = $_SESSION['varName']; //access your session here
    

    Post: Take a look at this.

    Another way is to include a hidden field in a form that submits to page two:

    <form method="post" action="header.php">
        <input type="hidden" name="varname" value="var_value">
        <input type="submit">
    </form>
    

    And then on header.php:

    //Using GET
    $var_value = $_GET['varname'];
    
    //Using POST
    $var_value = $_POST['varname'];
    
    //Using GET, POST or COOKIE.
    $var_value = $_REQUEST['varname'];
    

    Just change the method for the form to get if you want to do it via get.

    Happy Coding! :)

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制