Jump to content

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


wesleypipes

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]
Link to comment
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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.