473,801 Members | 2,316 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 3245
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
7226
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
2029
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
4202
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
2615
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
2456
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
2415
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
2092
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
2047
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
10515
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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...
0
9100
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7589
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
6827
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4156
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
3771
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.