php session should not accessible in different browser [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 days ago.
Improve this question
I started session with session_start() and set it like $_SESSION['auth'] = 1; and the url is something like localhost:8000/home after the login.
Now the problem is that why I am able to see my home page in different browser, it shouldn't be, just like google and stackoverflow pages after login. It should redirect me to the login page. How is that happening. How to destroy session on new browser?
if(isset($_SESSION['auth']))
{
session_destroy();
redirect('/login');
}

Try using session_unset() like this:
if(isset($_SESSION['auth']))
{
session_unset();
redirect('/login');
}

Related

How to use if else condition for login/logout in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am working on a e-commerce website. I want a help regarding displaying login & logout but when a user is logged in, user should only get logout option & when logged out user should get login option.
Please help me regarding this concept.
you can create SESSION variable (with email or any unique attribute) and set it when user LogsIn.
eg: session_start();
$_SESSION['email'] = useremail;
and check in every page if session varible is set or not.
session_start();
if(!isset($_SESSION)){
//then show login button
}
else{
//show logout button
}

Is it possible to differentiate the header while session activated [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
When user is logged in have to show logout otherwise it will show log in bar.... I am trying the bellow code :
<?php
if(session_start())
{
echo "<a href='home.php'>Logout</a>";
}
else echo " <a href='index1.php'>Login/Register</a>";
?>
// But this is not working. Kindly help
You are calling session_start() that will start the session. What you need to do is create the login script and then start the session. I would perhaps set a $_SESSION variable at this point like $_SESSION['logged_in'] = true. Then in the navigation header check for
if($_SESSION['logged_in'] === true){
// do something
}
That would perhaps be a better way to handle this.

Login Form, If Connected or Not-Connected [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm using the login form of this website http://www.html-form-guide.com/php-form/php-login-form.html, And i would like to display:
If you are connected, display Welcome ["name"]
Else if you are not, display Sign Up, Login.
I tried different ways, but it doesn't work. Could you help me please.
Thank you a lot, regards.
In addition with Mr.Alien answer, Use SESSION function to do this.
Put a user_id in session, show welcome message if session been set, show Sign up | Login if session not been set.
$_SESSION['user_id'];
if(isset($_SESSION['user'])) {
echo 'Welcome <username>';
}else{
echo 'Sign Up';
}

How to redirect to login page in php? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I had a problem facing that when we are in a page after login to the site then after some time we do loggedout from the page
Now my question is that after logged out if anyone copies the url and opened in the another browser it should be direct them to the login page
The code should contain the function
and that function should call in another php file like call function()
write below code on logout.php
session_start();
//or #session_start() if session already started before this line
session_destroy();
session_unset();
session_write_close();
session_regenerate_id(true);
$_SESSION = array();
header("Location:index.php");
exit();
more examples can be seen on session manual

Redirection of a webpage from one domain to another domain [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How to redirect a user from one domain to another after he has logged in ?
Using PHP
If you are runnig Apache this could be done through a .htaccess file, you could also send the user to a specific page when he/she logges in and at the top of that file use:
header('Location: http://your-redirection-uri.com';
exit();
Use header()
header("Location: http://www.example.com");
header('Location:http://www.xyz.com/abc.php');
xyz.com is new domain
write some session start code on abc.php file
and then redirect a page where u actually want to redirect
You could use:
header("Location: http://www.somedomain.com");
Hope it helps

Categories