Jump to content

Still cannot understand sessions.


u214

Recommended Posts

Hello guys. I'm back with a quick question that I don't seem to understand.

 

How exactly you create a session?

I know the very basics of it, and that includes:

<form action="Logged.php" method="post" >
    <input type="text" name="User" />
    <input type="password" name="Password" />
    <input type="submit" value="Login" />
    <input type="reset" value="Clear" />
</form>

Start with my log-in form.

 

This is called when you log-in:

				<?php
				include("config.php");
				if(isset($_SESSION["Username"]))
				{
					$user = $_SESSION["Username"];
					$pass = md5($_SESSION["Password"]);
				}
				else
				{
					$user = $_POST["User"];
					$pass = md5($_POST["Password"]);
					$_SESSION['Username'] = $user;
					$_SESSION['Password'] = $pass;

					$escuser = mysql_real_escape_string($user);
					$escpass = mysql_real_escape_string($pass);
				}

				$result = mysql_query("SELECT * FROM testWHERE user = '$escuser'");
				$num_rows = mysql_num_rows($result);
				if($num_rows == 0)
				{
					echo('That username does not exist...');
					echo '<a href="something.php"">  Go back!</a>';
					unset($_SESSION['Username']);
					unset($_SESSION['Password']);
					die;
				}

				$row = mysql_fetch_row($result);
				if($row[1] !== $escpass)
				{
				    echo('Wrong Password!...');
				    echo '<a href="something.php">  Go Back!</a>';
      					unset($_SESSION['Username']);
				    unset($_SESSION['Password']);
				    die;
				}
			?>

Like I said above, the very basics. On that Logged.php page ( Which I got the above code from ) does not have:

<?php  session_start(); ?>

 

^ That's what I am having trouble with. Am I supposed to add that on top of EVERY page I have?

 

I just need a quick rough-draft on how it should be, you don't need to use my examples, I just need to see a small preview of a log-in and then you can be able to access every page WHILE still logged.

 

Thanks.

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.