Welcome! Log In Create A New Profile

Advanced

confused smiley SESSION NOT WORKING - HELP PLEASE

Posted by 36903140-EW 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
confused smiley SESSION NOT WORKING - HELP PLEASE
May 09, 2012 03:33PM
Can someone please assist,

My sessions do not work. I have done what the PHP Manual sais, but to no avail and I have googled this thing blue.

I can login and get to 1 page, but everytime I click the menu link to go to another page it takes me to the login page......is there some PHP rule that I missed why it will not let me into my other pages?

Please help, I have been battling with this for a week and just have to get this done to hand in the portfolio.

Tx
confused smiley Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 03:46PM
Is your session section set on all the pages after your Login page?
Language: PHP
session_start(); if (!(isset($_SESSION[';login';]) && $_SESSION[';login';] != "")) { header ("Location:login.php"); }
confused smiley Re: Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 04:09PM
Yes,

I have even commented the header part just to get my Insert page to open, but yet it keep going to the login page...
if i echo the $_SESSION, it shows 1 on the login.page and 1 on the list.page, but i cannot get into the insert.php....no matter what i do.
confused smiley Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 04:40PM
Please attach your code where you created your session on your login page, and the code you inserted on your insert, list, edit, delete. Only the session part please.
confused smiley Re: Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 04:48PM
Login.php
Language: PHP
if ($result) { if ($num_rows > 0) { $_SESSION[';current';] = "1"; header("Location: list.php"); //$errorMessage = "Logged In"; } else { //if not a member, re-direct to registration page. $_SESSION[';current';] = ""; header("Location: register.php"); $errorMessage = "Invalid Login"; }
confused smiley Re: Re: Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 04:49PM
Oops, let me try that again
confused smiley Re: Re: Re: Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 04:51PM
What formatted code must I use?
confused smiley Re: Re: Re: Re: Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 05:00PM
list.php

Language: PHP
session_start(); //connect to the database include "connect.php"; // Check if logged in = session is set if (!isset($_SESSION[';current';]) && $_SESSION[';current';] != "") { //echo "session not set"; header("Location: login.php"); }
confused smiley Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 05:03PM
First you did not start your session.

Correct it by:

Language: PHP
if ($result) { if ($num_rows >0){ session_start(); $_SESSION [';current';] = "1"; header("Location:insert.php");

I added insert.php to mine so when the user log in they are taken to the insert page first.

The else part:

Language: PHP
//if not a member, re-direct to registration page session_start(); $_SESSION [';current';] = ';';; header("Location: register.php"); $errorMessage = "Invalid Login";

Note: in the else part you can either use: header("Location: register.php"winking smiley; or $errorMessage = "Invalid Login"; when you use the header it is going to direct you before you can read the Invalid login part!
confused smiley Re: Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 05:05PM
Sorry, my session_start() is at the top of my Login page. I tried it there coz it was not working at the bottom.
confused smiley Re: Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 05:06PM
in your list page keep your session code together

Language: PHP
<?php   //check to see if the user is logged on session_start(); if (!(isset($_SESSION[';current';]) && $_SESSION[';current';] != "")) { header ("Location:login.php"); } include(';connect.php';); //connection details to database in a connect.php page
confused smiley Re: Re: Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 08:32PM
Thank you very very much for your help, it was still not working though, so I decided to test it 'on-line', not on my pc and voila!!!

Think it was a Windows problem or something that did not understand the session thing.

smiling bouncing smiley
confused smiley Re: SESSION NOT WORKING - HELP PLEASE
May 09, 2012 08:57PM
Glad you got it to work, finished mine just now. smile
Good luck with your project!
confused smiley Re: Re: SESSION NOT WORKING - HELP PLEASE
May 10, 2012 08:30AM
Me too, I was ready to run away!
Thanks and same to you!!!!thumbs up
confused smiley Re: SESSION NOT WORKING - HELP PLEASE
May 10, 2012 01:34PM
Does the user have to log in first before access other pages like insert or list?
avatar
Mac
confused smiley Re: SESSION NOT WORKING - HELP PLEASE
May 10, 2012 02:58PM
Why post the same question in two topics Tumelo? Per the tut letter, I require order here. By posting like this you are misusing the forum sad smiley
avatar confused smiley Re: SESSION NOT WORKING - HELP PLEASE
May 11, 2012 09:47AM
mac I uploaded my project on the free web hosting but every thing was working perfectly either on my local computer or on the online server but now some time when I logged in and try to insert something , the insert button does not do any thing , when I logged out and relogged every thing starts working again.
What does it mean?
Any suggestion
avatar
Mac
confused smiley Re: SESSION NOT WORKING - HELP PLEASE
May 11, 2012 03:01PM
Those servers are sometimes slow and you have to be patient. That is all that could be wrong.
Sorry, you do not have permission to post/reply in this forum.