Jump to content

Archived

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

wesleypipes

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

Recommended Posts

[code]
<?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
}
?>
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.