473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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('session.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('session.use_cookies',false);
session_start();

$IMGVER_TS = (rand()%10);

$_SESSION["IMGVER_RT"] = $IMGVER_TS;

?>

<p align="center"> <?php echo $IMGVER_TS ?> <img src="deneimg.php?<?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_BLACK = imagecolorallocate ($IMGVER_IMAGE, 110,110, 110);
$IMGVER_COLOR_WHITE = imagecolorallocate ($IMGVER_IMAGE, 205, 205, 205);
imagefill($IMGVER_IMAGE, 0, 0, $IMGVER_COLOR_BLACK);

$IMGVER_RanText = $_SESSION["IMGVER_RT"];

imagechar($IMGVER_IMAGE, 3, 20, 0, $IMGVER_RanText ,$IMGVER_COLOR_WHITE);
header("Content-type: image/jpeg");
imagejpeg($IMGVER_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_trans_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_trans_sid set to off.

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

session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter 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_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path c:\Temp c:\Temp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_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.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_globals_jit On On
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_classes no value no value
disable_functions 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_string no value no value
error_log c:\php\error.txt c:\php\error.txt
error_prepend_string 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.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort 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_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
mail.force_extra_parameters no value no value
max_execution_time 30 30
max_input_time 60 60
open_basedir no value no value
output_buffering 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_argv Off Off
register_globals Off Off
register_long_arrays Off Off
report_memleaks On On
report_zend_debug On On
safe_mode On On
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from no value no value
sendmail_path no value no value
serialize_precision 100 100
short_open_tag Off Off
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 2M 2M
upload_tmp_dir no value no value
user_dir no value no value
variables_order GPCS GPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.ze1_compatibility_mode Off Off
Feb 19 '06 #1
1 5197
Putting ini_set('session.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******************************@giganews.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('session.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('session.use_cookies',false);
session_start();

$IMGVER_TS = (rand()%10);

$_SESSION["IMGVER_RT"] = $IMGVER_TS;

?>

<p align="center"> <?php echo $IMGVER_TS ?> <img src="deneimg.php?<?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_BLACK = imagecolorallocate ($IMGVER_IMAGE, 110,110, 110);
$IMGVER_COLOR_WHITE = imagecolorallocate ($IMGVER_IMAGE, 205, 205, 205);
imagefill($IMGVER_IMAGE, 0, 0, $IMGVER_COLOR_BLACK);

$IMGVER_RanText = $_SESSION["IMGVER_RT"];

imagechar($IMGVER_IMAGE, 3, 20, 0, $IMGVER_RanText ,$IMGVER_COLOR_WHITE);
header("Content-type: image/jpeg");
imagejpeg($IMGVER_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_trans_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_trans_sid set to off.

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

session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter 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_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path c:\Temp c:\Temp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_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.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_globals_jit On On
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_classes no value no value
disable_functions 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_string no value no value
error_log c:\php\error.txt c:\php\error.txt
error_prepend_string 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.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort 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_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
mail.force_extra_parameters no value no value
max_execution_time 30 30
max_input_time 60 60
open_basedir no value no value
output_buffering 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_argv Off Off
register_globals Off Off
register_long_arrays Off Off
report_memleaks On On
report_zend_debug On On
safe_mode On On
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from no value no value
sendmail_path no value no value
serialize_precision 100 100
short_open_tag Off Off
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 2M 2M
upload_tmp_dir no value no value
user_dir no value no value
variables_order GPCS GPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.ze1_compatibility_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
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...
6
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...
3
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...
6
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...
6
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...
2
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...
4
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...
3
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...
26
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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 projectplanning, coding, testing,...

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.