0

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?

  • you can store it in session variable and can use it any where in your application. or you can simply send using get or post method. it totally depends on your requirement. i would suggest to go for Session variable. Have a look at this : https://stackoverflow.com/questions/23730124/pass-variables-from-one-file-to-another-in-php and this one : https://stackoverflow.com/questions/871858/php-pass-variable-to-next-page – Deepa Jul 27 '17 at 08:57

1 Answers1

0

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! :)

Deepa
  • 184
  • 1
  • 2
  • 16
  • On successful login , you want to redirect after login to dashboard page and display the name and image over dashboard right ? – Deepa Jul 27 '17 at 09:21
  • Please post the full html code. you are posting partial code. – Deepa Jul 27 '17 at 09:29