Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

why dosent this set a session?

session

  • Please log in to reply
5 replies to this topic

#1 JakeWelton

JakeWelton

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 152 posts
  • Programming Language:Java, C++, C#, PHP, JavaScript, PL/SQL
  • Learning:Objective-C, Python, Perl, Ruby, Visual Basic .NET, Haskell

Posted 01 October 2010 - 02:18 PM

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
  • 0

#2 Calgon

Calgon

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 53 posts

Posted 01 October 2010 - 08:04 PM

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

#3 JakeWelton

JakeWelton

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 152 posts
  • Programming Language:Java, C++, C#, PHP, JavaScript, PL/SQL
  • Learning:Objective-C, Python, Perl, Ruby, Visual Basic .NET, Haskell

Posted 01 October 2010 - 11:33 PM

i have tried that but no luck. Any more ideas?
  • 0

#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 02 October 2010 - 06:54 AM

session_start() is to be called on ALL pages where you want to access the $_SESSION variable
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#5 JakeWelton

JakeWelton

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 152 posts
  • Programming Language:Java, C++, C#, PHP, JavaScript, PL/SQL
  • Learning:Objective-C, Python, Perl, Ruby, Visual Basic .NET, Haskell

Posted 03 October 2010 - 01:38 AM

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

#6 SoN9ne

SoN9ne

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 118 posts
  • Programming Language:Java, PHP, JavaScript, Bash
  • Learning:C, Objective-C

Posted 04 October 2010 - 05:54 AM

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.
  • 0
"Life would be so much easier if we only had the source code."





Also tagged with one or more of these keywords: session

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download