473,856 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sessions broken in PHP 5

I have a strange problem with sessions in PHP 5. I have a simple script that
prints a random number both as a string and a picture on the screen. When I
run the script for the first time, it works perfectly. However, when I
refresh the page, new updated random number does not propagate to the image
displayer script through sessions. The image displayer script continues
showing the old number instead of the new random number. I checked the
script on PHP 4.4.2 on Linux with Apache, and the script worked without any
problems. However, when I tried it on my computer using PHP 5.1.2 on Windows
with Apache 2, I got this problem. I used the same computer with IE6 for
browsing in both cases.

I did some debugging and saw that the problem is solved when I delete the
ini_set('sessio n.use_cookies', false); line. However, I need this line
because I do not want to use cookies.
These are the scripts:

The main script printing the numbers. When you run the script, the two
numbers written as text and image must be the same. When you first run the
script, they are the same. However, when you refresh the page, image still
shows the old number when PHP 5 is used.

Code:
<?php

ini_set('sessio n.use_cookies', false);
session_start() ;

$IMGVER_TS = (rand()%10);

$_SESSION["IMGVER_RT"] = $IMGVER_TS;

?>

<p align="center"> <?php echo $IMGVER_TS ?> <img src="deneimg.ph p?<?php echo
SID ?>"> </p>


This is the script for showing the image. The name of the script file is
deneimg.php

Code:
<?php

session_start() ;
$IMGVER_IMAGE = imagecreate(50, 20);
$IMGVER_COLOR_B LACK = imagecoloralloc ate ($IMGVER_IMAGE, 110,110, 110);
$IMGVER_COLOR_W HITE = imagecoloralloc ate ($IMGVER_IMAGE, 205, 205, 205);
imagefill($IMGV ER_IMAGE, 0, 0, $IMGVER_COLOR_B LACK);

$IMGVER_RanText = $_SESSION["IMGVER_RT"];

imagechar($IMGV ER_IMAGE, 3, 20, 0, $IMGVER_RanText ,$IMGVER_COLOR_ WHITE);
header("Content-type: image/jpeg");
imagejpeg($IMGV ER_IMAGE);
?>

Could you please check it?

I checked the temp directory for sessions. Session files are created
properly, so it is not the source of the problem.

Also, I think it is not a cache problem. I did refresh by pressing ctrl + f5
and it didn't solve the problem. Strange thing is that the same code is
working on when server is PHP 4.4.2 on Linux with Apache, but not working
when server is PHP 5.1.2 on Windows XP with Apache 2.0.55 connected to PHP
via ISAPI.

Session id's are being passed around the URL. Sessions are working when I
first load the page. When I do refresh, a new session id is injected to the
image displayer script, but the image displayer script is still showing the
data of previous session.

I tried the code by setting session.use_tra ns_sid to both on and off, but it
didn't solve the problem. The code is working perfectly fine on a server is
PHP 4.4.2 that has session.use_tra ns_sid set to off.

The session parameters of my server causing the problem are as follows:

session.auto_st art Off Off
session.bug_com pat_42 Off Off
session.bug_com pat_warn On On
session.cache_e xpire 180 180
session.cache_l imiter nocache nocache
session.cookie_ domain no value no value
session.cookie_ lifetime 0 0
session.cookie_ path / /
session.cookie_ secure Off Off
session.entropy _file no value no value
session.entropy _length 0 0
session.gc_divi sor 1000 1000
session.gc_maxl ifetime 1440 1440
session.gc_prob ability 1 1
session.hash_bi ts_per_characte r 5 5
session.hash_fu nction 0 0
session.name PHPSESSID PHPSESSID
session.referer _check no value no value
session.save_ha ndler files files
session.save_pa th c:\Temp c:\Temp
session.seriali ze_handler php php
session.use_coo kies On On
session.use_onl y_cookies Off Off
session.use_tra ns_sid 0 0

PHP core parameters are as follows:

allow_call_time _pass_reference Off Off
allow_url_fopen On On
always_populate _raw_post_data Off Off
arg_separator.i nput & &
arg_separator.o utput & &
asp_tags Off Off
auto_append_fil e no value no value
auto_globals_ji t On On
auto_prepend_fi le no value no value
browscap no value no value
default_charset no value no value
default_mimetyp e text/html text/html
define_syslog_v ariables Off Off
disable_classes no value no value
disable_functio ns no value no value
display_errors On On
display_startup _errors On On
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl On On
error_append_st ring no value no value
error_log c:\php\error.tx t c:\php\error.tx t
error_prepend_s tring no value no value
error_reporting 2039 2039
expose_php On On
extension_dir c:\php\ c:\php\
file_uploads On On
highlight.bg #FFFFFF #FFFFFF
highlight.comme nt #FF8000 #FF8000
highlight.defau lt #0000BB #0000BB
highlight.html #000000 #000000
highlight.keywo rd #007700 #007700
highlight.strin g #DD0000 #DD0000
html_errors On On
ignore_repeated _errors Off Off
ignore_repeated _source Off Off
ignore_user_abo rt Off Off
implicit_flush Off Off
include_path .;C:\php5\pear .;C:\php5\pear
log_errors On On
log_errors_max_ len 1024 1024
magic_quotes_gp c On On
magic_quotes_ru ntime Off Off
magic_quotes_sy base Off Off
mail.force_extr a_parameters no value no value
max_execution_t ime 30 30
max_input_time 60 60
open_basedir no value no value
output_bufferin g 4096 4096
output_handler no value no value
post_max_size 8M 8M
precision 14 14
realpath_cache_ size 16K 16K
realpath_cache_ ttl 120 120
register_argc_a rgv Off Off
register_global s Off Off
register_long_a rrays Off Off
report_memleaks On On
report_zend_deb ug On On
safe_mode On On
safe_mode_exec_ dir no value no value
safe_mode_gid Off Off
safe_mode_inclu de_dir no value no value
sendmail_from no value no value
sendmail_path no value no value
serialize_preci sion 100 100
short_open_tag Off Off
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_cal lback_func no value no value
upload_max_file size 2M 2M
upload_tmp_dir no value no value
user_dir no value no value
variables_order GPCS GPCS
xmlrpc_error_nu mber 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.ze1_compat ibility_mode Off Off
Feb 19 '06 #1
1 5217
Putting ini_set('sessio n.use_cookies', false); to image script solved the
problem. Thanks to arborint from DevNetwork.com for solving the problem.

I wonder why I should put it to image script. Isn't putting it to only the
main script enough? It is strange that the old code worked perfectly fine
without that line in PHP 4, but didn't work in PHP 5.
"Duncan" <aa*@ne.com> wrote in message
news:Fa******** *************** *******@giganew s.com...
I have a strange problem with sessions in PHP 5. I have a simple script
that prints a random number both as a string and a picture on the screen.
When I run the script for the first time, it works perfectly. However, when
I refresh the page, new updated random number does not propagate to the
image displayer script through sessions. The image displayer script
continues showing the old number instead of the new random number. I
checked the script on PHP 4.4.2 on Linux with Apache, and the script worked
without any problems. However, when I tried it on my computer using PHP
5.1.2 on Windows with Apache 2, I got this problem. I used the same
computer with IE6 for browsing in both cases.

I did some debugging and saw that the problem is solved when I delete the
ini_set('sessio n.use_cookies', false); line. However, I need this line
because I do not want to use cookies.
These are the scripts:

The main script printing the numbers. When you run the script, the two
numbers written as text and image must be the same. When you first run the
script, they are the same. However, when you refresh the page, image still
shows the old number when PHP 5 is used.

Code:
<?php

ini_set('sessio n.use_cookies', false);
session_start() ;

$IMGVER_TS = (rand()%10);

$_SESSION["IMGVER_RT"] = $IMGVER_TS;

?>

<p align="center"> <?php echo $IMGVER_TS ?> <img src="deneimg.ph p?<?php
echo SID ?>"> </p>


This is the script for showing the image. The name of the script file is
deneimg.php

Code:
<?php

session_start() ;
$IMGVER_IMAGE = imagecreate(50, 20);
$IMGVER_COLOR_B LACK = imagecoloralloc ate ($IMGVER_IMAGE, 110,110, 110);
$IMGVER_COLOR_W HITE = imagecoloralloc ate ($IMGVER_IMAGE, 205, 205, 205);
imagefill($IMGV ER_IMAGE, 0, 0, $IMGVER_COLOR_B LACK);

$IMGVER_RanText = $_SESSION["IMGVER_RT"];

imagechar($IMGV ER_IMAGE, 3, 20, 0, $IMGVER_RanText ,$IMGVER_COLOR_ WHITE);
header("Content-type: image/jpeg");
imagejpeg($IMGV ER_IMAGE);
?>

Could you please check it?

I checked the temp directory for sessions. Session files are created
properly, so it is not the source of the problem.

Also, I think it is not a cache problem. I did refresh by pressing ctrl +
f5 and it didn't solve the problem. Strange thing is that the same code is
working on when server is PHP 4.4.2 on Linux with Apache, but not working
when server is PHP 5.1.2 on Windows XP with Apache 2.0.55 connected to PHP
via ISAPI.

Session id's are being passed around the URL. Sessions are working when I
first load the page. When I do refresh, a new session id is injected to
the image displayer script, but the image displayer script is still
showing the data of previous session.

I tried the code by setting session.use_tra ns_sid to both on and off, but
it didn't solve the problem. The code is working perfectly fine on a
server is PHP 4.4.2 that has session.use_tra ns_sid set to off.

The session parameters of my server causing the problem are as follows:

session.auto_st art Off Off
session.bug_com pat_42 Off Off
session.bug_com pat_warn On On
session.cache_e xpire 180 180
session.cache_l imiter nocache nocache
session.cookie_ domain no value no value
session.cookie_ lifetime 0 0
session.cookie_ path / /
session.cookie_ secure Off Off
session.entropy _file no value no value
session.entropy _length 0 0
session.gc_divi sor 1000 1000
session.gc_maxl ifetime 1440 1440
session.gc_prob ability 1 1
session.hash_bi ts_per_characte r 5 5
session.hash_fu nction 0 0
session.name PHPSESSID PHPSESSID
session.referer _check no value no value
session.save_ha ndler files files
session.save_pa th c:\Temp c:\Temp
session.seriali ze_handler php php
session.use_coo kies On On
session.use_onl y_cookies Off Off
session.use_tra ns_sid 0 0

PHP core parameters are as follows:

allow_call_time _pass_reference Off Off
allow_url_fopen On On
always_populate _raw_post_data Off Off
arg_separator.i nput & &
arg_separator.o utput & &
asp_tags Off Off
auto_append_fil e no value no value
auto_globals_ji t On On
auto_prepend_fi le no value no value
browscap no value no value
default_charset no value no value
default_mimetyp e text/html text/html
define_syslog_v ariables Off Off
disable_classes no value no value
disable_functio ns no value no value
display_errors On On
display_startup _errors On On
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl On On
error_append_st ring no value no value
error_log c:\php\error.tx t c:\php\error.tx t
error_prepend_s tring no value no value
error_reporting 2039 2039
expose_php On On
extension_dir c:\php\ c:\php\
file_uploads On On
highlight.bg #FFFFFF #FFFFFF
highlight.comme nt #FF8000 #FF8000
highlight.defau lt #0000BB #0000BB
highlight.html #000000 #000000
highlight.keywo rd #007700 #007700
highlight.strin g #DD0000 #DD0000
html_errors On On
ignore_repeated _errors Off Off
ignore_repeated _source Off Off
ignore_user_abo rt Off Off
implicit_flush Off Off
include_path .;C:\php5\pear .;C:\php5\pear
log_errors On On
log_errors_max_ len 1024 1024
magic_quotes_gp c On On
magic_quotes_ru ntime Off Off
magic_quotes_sy base Off Off
mail.force_extr a_parameters no value no value
max_execution_t ime 30 30
max_input_time 60 60
open_basedir no value no value
output_bufferin g 4096 4096
output_handler no value no value
post_max_size 8M 8M
precision 14 14
realpath_cache_ size 16K 16K
realpath_cache_ ttl 120 120
register_argc_a rgv Off Off
register_global s Off Off
register_long_a rrays Off Off
report_memleaks On On
report_zend_deb ug On On
safe_mode On On
safe_mode_exec_ dir no value no value
safe_mode_gid Off Off
safe_mode_inclu de_dir no value no value
sendmail_from no value no value
sendmail_path no value no value
serialize_preci sion 100 100
short_open_tag Off Off
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_cal lback_func no value no value
upload_max_file size 2M 2M
upload_tmp_dir no value no value
user_dir no value no value
variables_order GPCS GPCS
xmlrpc_error_nu mber 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.ze1_compat ibility_mode Off Off

Feb 19 '06 #2

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

Similar topics

4
2790
by: Goalie | last post by:
Dear all, I have a script which checks whether a user is logged in and on which level. If he is not logged in, he will get the login screen. My problem is that the script works on the server of the ISP, but not on my local machine. I checked me php.ini files and also phpinfo on the ISP server. But what happens is that if I try to log in on my local server the session is started but not read by the next file, it returns again to the login...
6
6548
by: JJ | last post by:
Hi, I really need to use cookieless ASP sessions with ASP 3 (IIS5) Can I find out the session ID from the first page, then post it or send it with the url to the next page, then at the start of the next page asp, set the session ID from the value retrieved from the URL? How do you manually set the session ID?
3
2485
by: Maxime Ducharme | last post by:
Hi group We have a problem with sessions in one of our sites. Sessions are used to store login info & some other infos (no objects are stored in sessions). We are using Windows 2000 Server (IIS 5.0) with ASP 3.0 (no .NET on this site). Sometime, data in session is emptied. I say "sometime"
6
1283
by: Stephanie Stowe | last post by:
Hi. The VStudio group does not seem to get much action. I think ASP folks may be able to answer as well. I have a situation that I cannot understand why it is happening. I have an ASP app which I am debugging in Visual Studio.NET. I am trying to duplicate a situation with 2 users. I open a browser and access my site (local to my machine). I navigate to the page I am trying to test. I then run the same app from Visual Studio.NET by hitting...
6
3814
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
2
1264
by: Dave | last post by:
I have an asp app that uses session variables. The downside is if the connection to the server is broken at any point during a user's session, the user cannot get his/her data to the server. I know that the user's form or data entry sessions should be shorter and the user should be sending / saving data to the server often so that there is less likelihood of losing a lot of data but do you have other suggestions? For example parsing...
4
2652
by: fmaxwell | last post by:
Dear Group I have a very frustrating problem. I have been trying to make it more difficult to access external javascript files by using PHP sessions. This works beautifully locally (both in IE6 and IE7) and online in IE7, but frustratingly, online in IE6, the javascript does not render on the page, unless you refresh the page. Is there something different about the way IE6 handles sessions? Why
3
28352
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every developer needs to know how to use. This article explains the basics of PHP Sessions. Assumptions: Basic PHP knowledge is required (variables, arrays and such) HTML Forms. What are Sessions? Sessions are a way of storing data. When developing...
26
7953
by: Bookham Measures | last post by:
Hello We are planning to set-up a load balanced web environment. Accordingly, we are going to change the session management on our website from the classic ASP Session State and session variables, to a database method. Does any one have any pointers as to how I might approach this, so that I can have the same sort of functionality the ASP sessions give without having to create database columns for each session variable I wish to...
0
9916
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9762
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,...
0
11057
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
10696
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10782
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
10384
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
5761
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
5958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3201
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.