Search code examples
phpformsgmail-imapimap-open

How to fetch user's First Name in php using Gmail Credentials as input?


I earlier used imap_open function in php to validate credentials of users from a form and give them login to my website. Now I also want to print their name that can be fetched from Google Servers providing their credentials as input.

I want to Print something like "Hello $gmail->firstname to the website", by providing the same user credentials from form as input to php file.

Is there anyway to do this without using Open ID API ?

My php function to authenticate was similar to this:-

function validate($username,$password) {
    $username = strtolower($username);
    $server="{imap.gmail.com:993/imap/ssl}";
    $result=false;
    $result = imap_open($server,$username,$password);
    if($result) {
            return 1;
    }
    else {
            return 0;
    }
}

Solution

  • try php's explode() function.

    $string_array = explode("@",$string);
    echo $string_array[0];
    

    has ur answer.