Hi,
I am developing a website. In Login form , on successful login of user, i had created session variable $_SESSION['username'] and redirected to second page. In second page when i checked , isset($_SESION['username']) is returning false.
This is the first website I am developing. Do I have to change any settings in php.ini for sessions to work?
15 2350
Hi,
I am developing a website. In Login form , on successful login of user, i had created session variable $_SESSION['username'] and redirected to second page. In second page when i checked , isset($_SESION['username']) is returning false.
This is the first website I am developing. Do I have to change any settings in php.ini for sessions to work?
For us to *really* help and not just guess, we need to see your code. Please post it using [code] tags.
My guess is you're not starting the session with session_start().
Here is the code:
loginpage.php - <?php
-
session_start();
-
require('config.php');
-
-
if($_POST['submit'])
-
{
-
$username = $_POST['name'];
-
$password = $_POST['password'];
-
$mysql = mysql_connect($dbhost,$dbuser,$dbpassword);
-
mysql_select_db($dbdatabase,$mysql);
-
$loginsql = "select * from logins where username='" . $username ."' and password='". $password. "';";
-
$loginres = mysql_query($loginsql);
-
$numlogin = mysql_num_rows($loginres);
-
$row = mysql_fetch_assoc($loginres);
-
if($numlogin==1)
-
{
-
session_register('USERNAME');
-
session_register('SESS_LOGGEDIN');
-
$_SESSION['USERNAME'] = $row['username'];
-
$_SESSION['SESS_LOGGEDIN'] = 1;
-
if(isset($_SESSION['USERNAME']))
-
{
-
header("Location:".$config_basedir."index.php");
-
-
}
-
else echo"sessions not set";
-
}
-
else
-
echo "Incorrect Login, please try again";
-
-
-
-
}
-
require('header.php');
-
-
-
-
?>
-
-
<form name='loginForm' action='<?php $SCRIPT_NAME?>' method='POST'>
-
-
<table>
-
<tr>
-
<td> UserName : </td> <td><input type='text' name='name'></td>
-
</tr>
-
<tr>
-
<td> Password : </td> <td><input type='password' name='password'></td>
-
</tr>
-
<tr>
-
<td> </td> <td><input type='submit' name='submit' value='Login'></td>
-
</td>
-
</table>
-
-
</form>
-
-
-
-
-
<?php
-
require('footer.php');
-
?>
On successfull login of user , page is redirected to index.php which is using header.php index.php - <?php
-
-
require('header.php');
-
?>
header.php - <?php
-
session_start();
-
require('config.php');
-
$db = mysql_connect($dbhost,$dbuser,$dbpassword);
-
mysql_select_db($dbdatabase,$db);
-
?>
-
-
<html>
-
-
<head>
-
<title><?php echo $config_blogname; ?> </title>
-
<link rel='stylesheet' href='stylesheet.css' tyep='text/css'>
-
</head>
-
-
<body>
-
<div id='header'>
-
<h1><?php echo $config_blogname; ?></h1>
-
</div>
-
<div id='menu'>
-
<a href='index.php'>Home</a>
-
<a href = 'viewcat.php'> Categories </a>
-
<?php
-
if(isset($_SESSION['USERNAME']))
-
{
-
echo "<a href='logout.php'> Logout</a>".$_SESSION['USERNAME'];
-
echo "<a href='addcat.php'> Add Category </a>";
-
echo "<a href='addentry.php'> Add Entry </a>";
-
}
-
else
-
echo "<a href='loginpage.php'> Login </a> <a href='signup.php'> SignUp </a> ";
-
-
?>
-
</div>
-
<div id="bar">
-
<img src= "../shoppingcart/Sai.jpg" width="200px" height="250px" top="200px">
-
</div>
-
<div id='main'>
In header.php isset($_SESSION['USERNAME']) is returning false.
have u check in loginpage line 16 $row['username']; is return any thing?
Yes. It is returning username correctly. In loginpage
isset($_SESSION['USERNAME']) is returning true. But echo $_SESSION['USERNAME'] is not printing anything.
try changing your code in the index.php to: -
<?php
-
session_start();
-
require('header.php');
-
?>
-
-
I hope this helps!
try changing your code in the index.php to: -
<?php
-
session_start();
-
require('header.php');
-
?>
-
-
I hope this helps!
That shouldn't change anything but give you a notice for starting the session again.
Take lines 17 and 18 out of loginpage.php - this won't be the problem, but you don't need to use them.
I can't see anything wrong with what you posted.
We'll have to see if someone else can spot it.
try changing your code in the index.php to: -
<?php
-
session_start();
-
require('header.php');
-
?>
-
-
I hope this helps!
I tried this. Its working. Thanks. It helped me continue two of my stucked projects. Thank you sooo much
Sessions are working fine in Internet Explorer. But not in Mozilla Firefox . Can anyone tell me why is that and what should I do for that to work?
I tried this. Its working. Thanks. It helped me continue two of my stucked projects. Thank you sooo much
I'll be damned..
I tried this. Its working. Thanks. It helped me continue two of my stucked projects. Thank you sooo much
glad i could be of help.. ^^,
and for your next problem, what happens in IE that does not happen in mozilla..? can you expound on the problem..?
I'll be damned..
ahahaha! XD lucky strike..?XD
glad i could be of help.. ^^,
and for your next problem, what happens in IE that does not happen in mozilla..? can you expound on the problem..?
The solution you have suggested (to add session_start() in index.php) is working in IE but not in mozilla. In mozilla firefox the problem still persists.
try to take out these lines from your login.php: - session_register('USERNAME');
-
session_register('SESS_LOGGEDIN');
I tried but of no use.......
PHP is not browser-specific: it does not act differently in different browsers.
Try clearing your cache and cookies.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chewy509 |
last post by:
Hi Everyone,
I'll just start, and say I am not a PHP developer (I'm a sysadmin, who
has gotten lumped with a non-working website). But since I like to do
this type of stuff, I though I might...
|
by: jing_li |
last post by:
Hi, you all,
I am a newbee for php and I need your help. One of my coworker and I
are both developing a webpage for our project using php. We have a
copy of the same files in different location...
|
by: Jon Grieve |
last post by:
Hi,
I've been playing for a few days now with putting Objects in sessions
and maintaining that object during a session. This seems to be working
just fine, and I can see and use most of the...
|
by: leegold2 |
last post by:
Probably a newbie question about "state":
My problem is I have a search form, so user enters a keyword <enter>,
then this form posts to another page were the result are displayed. But
this...
|
by: Theo |
last post by:
Question for the group
The authentication system for the site Im working on seems to function
properly and all is good. A session keeps track of everything and a
cookie is used to accept or deny...
|
by: LMachado1 |
last post by:
I just started with php and I'm trying to make a simple interface as
follows:
- user is asked to input an integers, for example: how many students do
you want to enter?
- user is then shown a...
|
by: Gary W |
last post by:
Hello,
I have used SESSIONS on mission critical pages on my site, and if sessions
are not enabled / supoorted - these pages will fail.
When and why would a session fail? They do not store any...
|
by: Atte André Jensen |
last post by:
Hi
I'm developing a site where I'd like to store information during a users
visit. So far I've been using sessions, but as far as I can tell it's
not possible to control for how long a session...
|
by: Frinavale |
last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |