Jump to content


Photo

Is the format of this 'loggedon.php' program ok.


  • Please log in to reply
2 replies to this topic

#1 wesleypipes

wesleypipes
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 October 2006 - 05:32 PM

<?php

session_start();

if (!isset($_SESSION["authenticatedUser"]))

{
  $_SESSION["message"] = "Please Login";
  
  header("Location: login.php");

}
else
{

?>

<body>

<h2>Youre ok you are authenticated as <?php echo

$_SESSION["authenticatedUser"] ?> </h2>

<a href = "logout.php">logout</a>

</body>
</html>

<?php
}
?>


#2 shadow-x

shadow-x
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 30 October 2006 - 05:37 PM

It seems fine to me, why do you ask? are you getting an error message or just wanted to check the coding?

one way of checking the format and coding of the script is to simply run it on a webserver (either locally on a devlopment environment or on a webhost), If there are any real problems with the code php will give out an error message. Unless its something minor that wont affect the code, in which case it normally isn't worth worrying about anyway.



#3 wesleypipes

wesleypipes
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 October 2006 - 05:49 PM

Basically, I log in through a form, below is the code that proceeds

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("memberdir") or die(mysql_error());

$appusername = $_POST['login_name'];
$apppassword = $_POST['password'];

$result = mysql_query("SELECT * FROM `user` WHERE username = '$appusername' AND password = '$apppassword'");
if (mysql_num_rows($result) > 0) {
  $_SESSION['authenticatedUser'] = $appusername;
  header("Location: loggedon.php");
}
else {
  $_SESSION['message'] = "Could not connect as $appusername";
  header("Location: login.php");
}
?>

ok now if i log in with a valid user, i should get notifed and the first bit of code i post should do this if you get what i mean




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users