Jump to content

why dosent this set a session?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
welton122

welton122

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
hi all,

okay basically i am making a lil test script but for some reason this wont set a session?????? i am unsure why. Can anyone help me with this please?

Heres my code:

<?php


if (isset($_POST['submitted'])) {


$username = $_POST['username'];

$password = $_POST['password'];


if ($username == "test" && $password == "test")

{

	session_start(); 

	

	$_SESSION['admin'] = 1;

}

else 

{

	echo '<script type="text/javascript">

	alert("Incorrect username or password.");

	</script>';

}


}


?>


<?php


include_once('header.php');


echo '<div id="login"><br><br><br><br>

		<center>

		<form action="login.php" method="POST">

		<fieldset style="width:500px; height: 170px;">

		<legend>

		  Staff login   

		</legend><br>

		Username: <input type="text" name="username">

		<br><br>

		Password: <input type="password" name="password"> 

		<br><br><br>

		<input type="hidden" name="submitted" value="TRUE">

		<input style="font-family:Arial, Helvetica, sans-serif;color:#6294A8;font-size:12px; height: 25px; width: 100px" type="submit" value="Login" name="login">

		</fieldset>

		</form>

		</center>

		<br><br><br><br>

</div>';


?>

Many Thanks,
J

#2
Calgon

Calgon

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Add
session_start();
to the top of your page, where it isn't ruined by conditionals, that should fix your problem.

#3
welton122

welton122

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
i have tried that but no luck. Any more ideas?

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
session_start() is to be called on ALL pages where you want to access the $_SESSION variable
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
welton122

welton122

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
I know that but I could not get the session to start, it docent matter know though because I am using cookies instead. Thanks for all the replys.

#6
SoN9ne

SoN9ne

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
Cookies are not safe and should not be used if security is a concern. Cookies can easily be tampered with and are not as secure as sessions. I suggest reading the PHP manual.
"Life would be so much easier if we only had the source code."