473,671 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session problem

leo
Hi , i have a problem with session variables.
The web site was already working correctly using sessions, i've had to
add a page which use a new variable session but this new one doesn't
get registered, so when the page redirect to another one the new
variable is vanished.
Here a snippet of the code:

<?php

unset($_SESSION['tipopreventivo ']);

//debug
$hand=fopen("pu blic/test.txt","w");
fwrite($hand,pr int_r($_POST,tr ue));
fclose($hand);
//

if(!empty($_POS T))
{
$error=array();
session_registe r('typep');
$_SESSION['type']=($_POST['type']?$_POST['type']:'Default');

//debug
$hand=fopen("pu blic/session.txt","w ");
fwrite($hand,pr int_r($_SESSION ,true));
fclose($hand);
//

if($_POST['info']==1)
{
$url="Location: prev.php";
header($url);
}

}
after submit text.txt e session.txt are right, in particular in
session.txt the variable $_SESSION['type'] is set ad has a value but
after the redirect to prev.php $_SESSION['type'] is not set
The sessions are working becouse other variables are passed correctly.
Any idea of what is wrong?

Jul 23 '07 #1
1 3233
On Jul 23, 6:05 pm, leo <leofante_XNOSP A...@gawab.comw rote:
Hi , i have a problem with session variables.
The web site was already working correctly using sessions, i've had to
add a page which use a new variable session but this new one doesn't
get registered, so when the page redirect to another one the new
variable is vanished.
Here a snippet of the code:

<?php

unset($_SESSION['tipopreventivo ']);

//debug
$hand=fopen("pu blic/test.txt","w");
fwrite($hand,pr int_r($_POST,tr ue));
fclose($hand);
//

if(!empty($_POS T))
{
$error=array();
session_registe r('typep');
$_SESSION['type']=($_POST['type']?$_POST['type']:'Default');

//debug
$hand=fopen("pu blic/session.txt","w ");
fwrite($hand,pr int_r($_SESSION ,true));
fclose($hand);
//

if($_POST['info']==1)
{
$url="Location: prev.php";
header($url);
}

}

after submit text.txt e session.txt are right, in particular in
session.txt the variable $_SESSION['type'] is set ad has a value but
after the redirect to prev.php $_SESSION['type'] is not set
The sessions are working becouse other variables are passed correctly.
Any idea of what is wrong?
session_registe r is deprecated and you do not need it at all. However,
if you use it, you first define the variable $type = ..., then say
session_registe r( "type" ). You don't need it since in the line below
you use the right way of setting session variables ($_SESSION["type"]
= ...). Also, you seem to have misspelled the "type" in
session_registe r ("typep"). All of these are just comments. As for why
it doesn't work, you should check whether you called session_start in
the right place (before any output has been made) and whether you
called it at all in this new file. You are probably aware that you
need it? Also, if you actually require-d this code into another file,
you might have called session_write_c lose before you require-d it.
That might be a problem as well. I don't know how this http header
works, but maybe the client doesn't get the generated session id (if
it's a new session), so it might not be recognized on the next file
request. Maybe you rethink the redirection method to redirect it by
either javascript or meta tags? Or simply require-ing the file you
need to redirect the client to? Without any further knowledge of your
code, I can't really guess anything else...

Cheers,
Darko

Jul 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7211
by: Billy Jacobs | last post by:
I am having a problem with my session variable being set to Null for no apparent reason. I am declaring it like the following when the user logs in. dim objUserInfo as new clsUserInfo 'Set some properties objUserInfo.UserName = txtUserName.text.trim objUserInfo...
1
2020
by: Scott Wickham | last post by:
I'm having a problem saving session information on one form and retrieving it on a subsequent form...for only one out of a number of users. Actually, I'm not absolutely certain it's a session problem but I'm hoping the experts can help me figure that out. Our application uses a session variable to "pass" info from one form to the next. It has always worked fine for our users until a few weeks ago when one of our users started having a...
6
656
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter, but I can't get the value is stored in it. How can I do that? Thanks a lot!
7
4193
by: Ottar | last post by:
I've made a program sorting incomming mail in public folder. The function runs every minute by using the form.timer event. In Access XP it runs for weeks, no problem. Access 2003 runs the same code for 6 hours and stops. I've found the problem to be the Set MySession = CreateObject("MAPI.Session")
5
2602
by: Mark Rodrigues | last post by:
Hi Everyone, I have been fighting a problem for a while and I wonder if someone out there can help. This problem has been presented in a number of news postings previously but I am yet to see a response with a suitable resolution. So here goes ... We have a web site which stores an instance of a class into a Session, which is used in a number of pages. The code looks something like:
9
2449
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example at http://www.lamartin.com/dotnet/sessiontestset.aspx, were I set Session, Application and Cache variables on the first page and then on the second page view them as the second page is refreshed every five seconds. Before 10 refreshes, the...
1
737
by: Werner | last post by:
Hi Patrick! Can you give an example of how to use a frameset inside an aspx-file? When I create a new frameset in Visual Studio.Net it just gives me a htm-File. Or give me a link where I can find one? Thanks Werner P.S. Somehow I did not manage to do a followup in Googles newsgroups.
1
2406
by: Johan Nedin | last post by:
Hello! I have a problem with SQLSession state on my ASP.NET pages. SQLSession state behaves very different from InProcess session state, which I think is very bad. I can understand some of the differences, e.g that every object you store in SQLSession state have to be serializable, but other differences are very unfortunate.
5
2081
by: Just D. | last post by:
Do we have any access to the Session object from a different Session? The idea is to save Session of a current user and then if he logs in again then return the Session back. It's not a problem to store, there is only one complicated object in this Session, but to get it on SessionStart to make a copy this is a problem. Maybe using Application or whatever? Or this data is divided and inaccessible anyway? Just D.
7
2036
by: Mr Newbie | last post by:
I have written a Custom Control Menu. Its fairly simple but it works well enough. In order to simplify things I decided to store the Menu1 custom control in Session. In the page load event below, it retreives the Menu from session and assigns its reference to Menu1. Within the Page_Load event I can see its internal values which have been retreived for each menu item and so it looks good. However, when the Render method is called of...
0
8483
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8603
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8673
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6236
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2818
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.