0
First of all I want to warn you that I am a beginner in PHP and I appreciate help because I need to deliver a work and I am in Deadline
I have a login button and I want you to switch to logout when the session is started but the condition works for multiple pages!
This is the code of my login.php page to which the login button sends the user when it is clicked!:
<div class="inner_container">
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="username" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<button class="login_button" name="login" type="submit">Login</button>
<a href="registo.php"><button type="button" class="register_btn">Criar conta</button></a>
</div>
</form>
<?php
if(isset($_POST['login']))
{
@$username=$_POST['username'];
@$password=$_POST['password'];
$query = "select * from user where username='$username' and password='$password' ";
$query_run = mysqli_query($con,$query);
if($query_run)
{
if(mysqli_num_rows($query_run)>0)
{
$row = mysqli_fetch_array($query_run,MYSQLI_ASSOC);
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
header( "Location: index.php");
}
else
{
echo '<script type="text/javascript">alert("Nome de utilizador ou palavra passe inválida")</script>';
}
}
else
{
echo '<script type="text/javascript">alert("Database Error")</script>';
}
}
else
{
}
?>
</div>
You’ve done the routine to delete the session?
– Sam
How so?????
– AlmostDone
When the person clicks on to drop, you will delete the session, right?
– Sam
I didn’t try to do that! But I will have to make a condition to echo or not?
– AlmostDone
You want to put a logout button on all pages, including the login?
– Sam
I have other pages besides index.php which is the page to which the user will log in correctly! I just need the login button that changes to logout when the user logs in correctly! And when you have the logout button and it is pressed that change to login I tried to do several conditions and I am not getting there...
– AlmostDone
From what I understand, you can put the logout button on the pages by checking Session with IF, and on the login page redirect to the index if SESSION is full
– Sam
I’ve seen people do it but make a page where they have the login button and the logout button and when you log in correctly send to the page that have the logout button and when that logout sends to the page that have login but I have several pages I will not duplicate my pages to do this there must be a better way?
– AlmostDone
No need to duplicate anything. Using IF you can check if SESSION is full and show a button or other.
– Sam
I’m tempted what Leonardo Duarte is trying to help me!
– AlmostDone