Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 10th, 2005, 6:00 AM   #1
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
trouble with sessions

Hi there. I am stuck on sessions again!.

I am creating a session

<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix

error_reporting(E_ALL);



Then a session variable

$_SESSION['access'] = $access;


This is created in the directory www.website.com/home.php

I then want to access this variable on a page www.website.com/helpdesk/home.php as below

<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix

error_reporting(E_ALL);


if(isset($_SESSION['access']) == false)
{
$URL="http://www.google.co.uk";
header ("Location: $URL");
}

But it dosn't pick up the variable. The above if statement always returns false.

Any help??
Thanks in advance
k4pil is offline   Reply With Quote
Old Nov 10th, 2005, 6:58 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Read the forum's FAQ/rules and learn how to use code tags.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 10th, 2005, 7:52 AM   #3
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
sorry about the code tags. Will do for next time.

Any help with the question??
k4pil is offline   Reply With Quote
Old Nov 10th, 2005, 10:13 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Well, your links are no good for assessing your PHP code. They just lead to pages. If you want your session variables to persist, you have to have session continuity either via cookies or as part of the url. If cookies are disabled, there goes that one. Whether or not you have to overtly put the SID in the url depends upon a couple settings. Have you inquired of the PHP manual? Checked those settings? Read up on sessions?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 10th, 2005, 10:36 AM   #5
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
I have had a look into sessions. I havn't come acroos continuity. I understood if session start() was used the the session continued.

no?
k4pil is offline   Reply With Quote
Old Nov 10th, 2005, 10:42 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Suppose your server receives a request from some client. How does your server know that it's a continuing session from a previous request by that client? Http is stateless. It's the provision of a valid session ID by the client that signals continuity. The client provides that via cookie, or via the URL. Again, all this is covered in the PHP manual, which is excellent documentation. If the stateless nature of the client/server paradigm is news to you, you need to brush up on that, also.

If you don't have a lot of session variables, you can keep state information yourself, in much the same way that PHP does. It's really just a convention that someone else has taken the trouble to write for you.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:25 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC