Jump to content

Session variable problem.


Dark57

Recommended Posts

So I'm trying to make a login script, and when it detects that you've logged in correctly you are directed towards a page that has your personal information on it.  I am trying to do this using a session, but whenever I get directed to the page it says that the variable is undefined.

 

This is what I have for when they login correctly.

<?php
// Check if session is not registered , redirect back to main page.

session_start();
if(!session_is_registered(myusername))
{
header("location:main_login.php");
}
?>
<html>
<body>

<?php
$_SESSION['username']==$_POST['myusername'];
header("location:index.php");
?>
</body>
</html>

 

Then this line of code right here should display their username if I'm not mistaken.

<?php echo $_SESSION['username']; ?>

 

Now I might not be catching a simple mistake but I've been staring at it for a while and tried reading up on it and from what I can see I don't see me doing anything wrong. Any help would be appreciated.

 

Oh I forgot, this is the error message I am getting.

Notice: Undefined variable: _SESSION in C:\wamp\www\Silent Night Online\Index.php on line 26

Link to comment
https://forums.phpfreaks.com/topic/197944-session-variable-problem/
Share on other sites

Have you got session_start() on all pages that use sessions? Also, this....

 

if(!session_is_registered(myusername))

 

should be....

 

if(!isset($_SESSION['myusername']))

 

session_is_registered is deprecated and you where also trying to use an undefined constant myusername.

I'm still getting the same problem.  So I looked into my user login check script.  If session_is_registered() is deprecated then will this also be deprecated?

 

session_register("myusername");
session_register("mypassword");

 

Yes.

 

Ok I tried changing that line of code to but I'm still getting the same error.

$_SESSION['username']=$_POST['myusername'];
$_SESSION['password']=$_POST['mypassword'];

 

Again, have you got session_start() on all pages that use sessions?

Archived

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

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