Jump to content

$_SESSION problems.


phpparty

Recommended Posts

I am fairly new to php and I am having some problems figuring out what I am doing wrong for a simple login I am doing. There is a login form which calls this page:

 

<?php

session_start();

session_register("user");

$username = $_POST['username'];

$password = $_POST['password'];

require_once("connect.php");

$querystring = "SELECT * FROM tbl_users WHERE user_username='".$username."' AND user_password='".$password."'";

$loginresult = mysql_query($querystring);

$howmany = mysql_num_rows($loginresult);

if($howmany == 1) {

$_SESSION['user'] = "yes";

header("Location: cms.php");

}else{

header("Location: login.php");

}

?>

 

This form does work I believe because if I enter a valid username and password I am taken to the "cms.php" page, and if the username or password is wrong I am taken to the login page again. The problems arise when I start trying to restrict the actions of the php depending on the user being logged in or not. This code, despite the user being logged in or not, while always return nothing:

 

if(isset($_SESSION['user'])) {

require_once("connect.php");

$portstring = "SELECT * FROM tbl_portfolio ORDER BY portfolio_id ASC";

$newsstring = "SELECT * FROM tbl_news ORDER BY news_id ASC";

$portinfo = mysql_query($portstring);

$newsinfo = mysql_query($newsstring);

}else{

 

}

 

Any help that can be provided would be greatly appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/155720-_session-problems/
Share on other sites

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.