Jump to content

Yo!


Toy

Recommended Posts

I'm doing something for the fun of it but I've kinda reached a problem!

 

I have the login and index page on the same...eh, page, so I log in using the "login form" and it works fine, but I want it so that after i login the login form dissapears, I tried assigning a cookie to fix this but I can't go that way so yeah, help me!

Link to comment
https://forums.phpfreaks.com/topic/225787-yo/
Share on other sites

<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$password=md5($password);
$sql="SELECT xx FROM xx WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
echo 'This part is only visible if logged in!';
}
else
{
echo 'Sorry! The details you provided were incorrect, please try again...';
}
}
?>

<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
Username: 
<input type='text' name='username' class='input'>
Password: 
<input type='password' name='password' class='input'>
<input type='submit' value='Login' class='input'>
</form>

Link to comment
https://forums.phpfreaks.com/topic/225787-yo/#findComment-1165656
Share on other sites

<?php
session_start();

if(!isset($_SESSION['logged_in'])) {
$_SESSION['logged_in'] = false;
}

if($_SESSION['logged_in'] == false)
{
if($_SERVER["REQUEST_METHOD"] == "POST") {
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$password=md5($password);
$sql="SELECT xx FROM xx WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
$_SESSION['logged_in'] = true;
header("Location: ".$_SERVER['PHP_SELF']);
}
else
{
echo 'Sorry! The details you provided were incorrect, please try again...';
}
}
} else {
// Use it here instead
echo 'This part is only visible if logged in!';
}
?>

<?php if($_SESSION['logged_in'] == false) { ?>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
Username: 
<input type='text' name='username' class='input'>
Password: 
<input type='password' name='password' class='input'>
<input type='submit' value='Login' class='input'>
</form>
<?php } ?>

 

In theory the above will work. It may need a little modification as I have not tested it.

Link to comment
https://forums.phpfreaks.com/topic/225787-yo/#findComment-1165657
Share on other sites

<?php
session_start();

if(!isset($_SESSION['logged_in'])) {
$_SESSION['logged_in'] = false;
}

if($_SESSION['logged_in'] == false)
{
if($_SERVER["REQUEST_METHOD"] == "POST") {
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$password=md5($password);
$sql="SELECT xx FROM xx WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
$_SESSION['logged_in'] = true;
header("Location: ".$_SERVER['PHP_SELF']);
}
else
{
echo 'Sorry! The details you provided were incorrect, please try again...';
}
}
} else {
// Use it here instead
echo 'This part is only visible if logged in!';
}
?>

<?php if($_SESSION['logged_in'] == false) { ?>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
Username: 
<input type='text' name='username' class='input'>
Password: 
<input type='password' name='password' class='input'>
<input type='submit' value='Login' class='input'>
</form>
<?php } ?>

 

In theory the above will work. It may need a little modification as I have not tested it.

 

Thank you!

 

I now get a "Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs"

 

on line:

 

header("Location: ".$_SERVER['PHP_SELF']);

 

very tired right now, sry if I'm bothering you with something stupid

Link to comment
https://forums.phpfreaks.com/topic/225787-yo/#findComment-1165663
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.