Unstoppable Domains

PHP Session Help

Spaceship Spaceship
Watch

Ik

Quality //VIP Member
Impact
8
I need help!

I'm using sessions to protect some pages from unauthorized users.

Here is my code:

When there is a match in the database:

Code:
session_start();
session_register("username");
header("location:index.php");

In the protected page:

Code:
session_start();
if(!isset($_SESSION['username']))
{
	header("location:login.php");
}

The code works perfectly on my local machine, but when I upload to dreamhost.com it keeps redirecting me to the login page regardless I type the wrong credentials or the right ones. The database is fine, and the tables include the login information the I use to log in!

Any thoughts??
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
Do not use session_register - that requires register_globals and long story short - it is BAD.

PHP:
<?php

session_start();

$_SESSION['username'] = $username;
$_SESSION['loggedin'] = true;

header("Location: index.php");
exit;

?>

...

PHP:
<?php

session_start();

if (!isset($_SESSION['username'], $_SESSION['loggedin']) OR $_SESSION['loggedin'] != true)
{
        header("Location: login.php");
        exit;
}

?>
 
0
•••
First thing is to verify if the $_SESSION variable is set.
This function is deprecated as of PHP6. Which version is your host using ?
 
0
•••
you are a php guru :) it works, thanks a lot

Do not use session_register - that requires register_globals and long story short - it is BAD.

PHP:
<?php

session_start();

$_SESSION['username'] = $username;
$_SESSION['loggedin'] = true;

header("Location: index.php");
exit;

?>

...

PHP:
<?php

session_start();

if (!isset($_SESSION['username'], $_SESSION['loggedin']) OR $_SESSION['loggedin'] != true)
{
        header("Location: login.php");
        exit;
}

?>


---------- Post added at 05:25 PM ---------- Previous post was at 05:21 PM ----------

First thing is to verify if the $_SESSION variable is set.
This function is deprecated as of PHP6. Which version is your host using ?

Thanks :)
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back