Google OAuth Login Demo
Click the button below to login with your Google account:
Sign in with Google
Debug Info:
Session ID: fr6263tfnrqnvrmad5e346nrso
Session State Set: Yes (9dcd06440fc839b6fa4316e79af2af3a)
Cookie State Set: No
Current URL: /
Server Name: dveasy.com
HTTPS: Yes
Session Save Path: /tmp/php_sessions
Session Save Path Writable: Yes
PHP Session Module: files
Test Session
Configuration Check:
Client ID Set: ✓ Yes
Client Secret Set: ✓ Yes
Redirect URI: https://www.dveasy.com/index.php
Database Host: srv1387.hstgr.io
Database Name: u669301026_jazz
cURL Available: ✓ Yes
allow_url_fopen: ✓ Enabled
Outbound HTTPS (file_get_contents): ✗ Blocked
Outbound HTTPS (cURL): ✓ Working
Setup Instructions:
Google Console Setup:
Go to Google Developers Console
Create a new project or select existing one
Enable the "Google+ API" and "Google OAuth2 API"
Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client ID"
Add your domain to authorized redirect URIs
Copy your Client ID and Client Secret
Database Setup:
Create a MySQL database
Update the database configuration variables at the top of this file
Configuration:
Update $google_client_id and $google_client_secret
Update $redirect_uri to match this file's URL
Update database connection details
Troubleshooting "Outbound HTTPS Blocked" Error:
Your server cannot make HTTPS requests to external sites (like Google). This is a common hosting restriction.
Solutions (in order of preference):
Contact Your Hosting Provider:
Ask them to enable outbound HTTPS requests
Request they whitelist Google's OAuth endpoints: *.googleapis.com
This is the best long-term solution
Enable cURL (if available):
The code now automatically tries cURL as a fallback
Check if "cURL Available" shows green in the debug info above
Some hosts block file_get_contents but allow cURL
Use a Proxy Service:
Set up a proxy on another server that can make HTTPS requests
Route your OAuth requests through the proxy
Move to a Different Host:
Consider VPS hosting (DigitalOcean, Linode, AWS)
Most modern hosting providers allow outbound HTTPS
Alternative: Server-Side Proxy Script:
Create a proxy script on a different server
Have your main server communicate with the proxy via HTTP
Quick Tests to Try:
Check both HTTP methods: The debug info now shows both file_get_contents and cURL results
Try HTTP instead of HTTPS: Some hosts block only HTTPS (not recommended for production)
Test from command line: SSH into your server and try curl https://www.google.com
Hosting Provider Specific Solutions:
Shared Hosting: Often blocks outbound requests - contact support
cPanel/WHM: Check if "Allow outbound connections" is enabled
Cloudflare: Not the issue - this is server-level blocking
Note: This is a server configuration issue, not a code problem. The OAuth flow requires your server to communicate with Google's servers.
Troubleshooting "Failed to get access token" Error:
Troubleshooting "Failed to get access token" Error:
This error occurs during the token exchange with Google. Common causes:
Outbound HTTPS Blocked: Your server can't connect to Google (see section above).
Incorrect Client Secret: Double-check your $google_client_secret in the code.
Redirect URI Mismatch: The $redirect_uri in your code must EXACTLY match what's in Google Console.
Wrong Client ID: Verify your $google_client_id is correct.
Expired Authorization Code: Don't click browser back/forward or wait too long between steps.
Code Already Used: Each authorization code can only be used once.
Google Console Checklist:
Go to Google Console Credentials
Click on your OAuth 2.0 Client ID
Check "Authorized redirect URIs" - it must include: https://www.dveasy.com/index.php
Make sure both "Google+ API" and "Google People API" are enabled in your project
Verify you're using the correct Client ID and Secret from the right project
Quick fixes:
First: Check if "Outbound HTTPS (cURL)" shows green in debug info above
Copy fresh credentials from Google Console
Make sure there are no extra spaces in your credentials
Try the login process in a fresh browser session
If both HTTPS methods are blocked, contact your hosting provider
Troubleshooting "Session expired" Error:
If you're getting "oauth_state not found in session" error:
Session directory not writable: Check if the session save path (shown in debug info) is writable by PHP.
Session cookies blocked: Make sure your browser accepts cookies.
Different domains: Ensure you're not switching between www and non-www versions.
Session configuration: Check if PHP sessions are properly configured on your server.
Multiple server instances: If using load balancing, sessions might not be shared.
Quick session tests:
Test sessions work: Add $_SESSION['test'] = 'working'; at the top, then refresh and check if it persists.
Check permissions: Make sure the session directory has proper write permissions (755 or 777).
Try different browser: Test in a completely different browser.
Check server logs: Look for PHP errors in your server's error log.
Alternative solutions:
The code now includes a cookie fallback mechanism that should work even if sessions fail.
If still failing, your hosting provider might have session restrictions.