Sessions broken in PHP 5

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Duncan

    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


  • Duncan

    #2
    Re: Sessions broken in PHP 5

    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" <aaa@ne.com> wrote in message
    news:FaGdnT8DSN L-mmXenZ2dnUVZ_tS dnZ2d@giganews. com...[color=blue]
    >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
    >[/color]


    Comment

    Working...