I am building a website for a class the following is my code for google sign in.
ID: 3847524 • Letter: I
Question
I am building a website for a class the following is my code for google sign in.
The follwoing code is for the index page where the user first visits. Once they login with google they are redirected to the homepage.
How can I make it so the homepage is not accesible to anybody that is not signed in. Currently if i type the url in the web browser i still have access to the home page. What code can I add to the home page??
Home page
K?php class GoogleAuth protected $db; protected $client; public function construct(DB $db null, Google Client $googleClient null) $this->db $db; $this- client $googleClient. ($this->client $this- client->setclientid('361982001136-ghjdqd7kb74h1vaii.apps.googleusercontent.com'); $this- client- setclientsecret('7Pgq6b164GR7y'); $this- client->setRedirectUni('https://the-coyote-xchange-emmanuelgi13546904.codeanyapp.com/index.php'); $this- client->se tScopes( email') public function isLoggedIn() return isset SESSION 'access token'D public function getAuthurl() return $this->client- createAuthurl public function checkRedirectCode() if(isset GETC' code'])) $this- client- authenticate($ GETC'code' J); $this- set Token ($this client->getAccessToken()) $this-> storeUser($this->getPayload()) return true; return false;Explanation / Answer
Steps For Preventing User From Accessing the Website until he Logs In
if($_SESSION['user is logged in']==1){ Show the HomePage}
else {Redirect the user to login page }
Code For Example
<?
session_start();
if(!$_SESSION['logged_in']){
header("Location: HTTP/1.1 404 File Not Found", 404);
session_unset();
session_destroy();
exit;}
else if($_SESSION['logged_in']){
header("Location: http://localhost:8080/coyote_xchange/home.php1 ")
}
?>
Please rate the answer if it helped.... Thankyou
Hope it helpss....
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.