Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    does session_start() reset the session vars ?

    Hello,

    Am a bit new to using sessions and I have got a bit confused.

    I am passing a session variable for the captha image.


    My index.php starts off with:
    PHP Code:
    <?php 
    /*
    *  index.php
    *

    *  calls my_functions.php
    *  and  first_page_fm.php
    *  and  a_client_chk.php
    *  and  b_email_act.php
    *  and  confirm_disp.php
    *
    *  
    */
    session_start()

    require_once(
    "my_functions.php");

    now later on it includes a form script:

    PHP Code:
    require_once("first_page_fm.php");    // run BIG FORM
    exit(); 
    Inside the form the captcha script is run with the image
    like this:

    PHP Code:
    <span class="tab-cell-right"  style="height: 40px; "><img src="captcha.php"> </a></span
    Inside captcha.php

    the session var is set:

    PHP Code:
    $_SESSION['key'] = md5($string); 

    Now the form script re-runs index.php
    which processes the form data.

    i.e.
    PHP Code:
    <form name="main_fm1" action ='index.php' method 'POST'
    So when the index re-runs (from the form) and the "session_start()" is encountered again, does the $_SESSION['key'] variable get lost ?

    or does the "session_start()" pass it on ?

    If passed on, this code should display it:

    PHP Code:
    $keytxt =$_SESSION['key'];

    ECHO 
    "Keytext: $keytxt"
    But it shows up as empty

    Any ideas on what I am doing wrong ?

    Thanks for any input.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    Each page that sets or uses any session variable must contain a session_start() (how else do you suppose it works?). If captcha.php does not have a session_start() add one.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    OK - thanks

    I am going to put session_start() into the capctha.php

    but I thought if it goes in there I will get those "headers already used" type error as this capctha.php is being called in the middle of my html form (after I've already sent lots of stuff to the browser) with the image statement like this:

    PHP Code:
    <span class="tab-cell-right"  style="height: 40px; "><img src="captcha.php"> </a></span
    If it doesn't error - why not ?

    ( just want to understand it better )

    Thanks again
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    The URL listed in the <img src="..." alt=""> tag is fetched separately by the browser.

    Here is how images on web pages work.

    The browser requests a web page (such as your form.) The HTML code on that page is output to the browser. In your case you have an image and the HTML code is - <img src="captcha.php">. The browser sees the src="..." parameter and generates a http request to the web server to fetch the image. Any php code in captcha.php is not executed until the browser fetches the image.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    The URL listed in the <img src="..." alt=""> tag is fetched separately by the browser.

    Here is how images on web pages work.

    The browser requests a web page (such as your form.) The HTML code on that page is output to the browser. In your case you have an image and the HTML code is - <img src="captcha.php">. The browser sees the src="..." parameter and generates a http request to the web server to fetch the image. Any php code in captcha.php is not executed until the browser fetches the image.
    I'm also trying to create a Captcha for a form. Inside "captcha.php" i try to register/store the code that is randomly generated: $_SESSION["captcha"] = 'xxx'; However, nothing is written in the session file.

    The session_start() command is present at the begining of both files (captcha.php and .html).

    What can I do?

    Any help would be really apreciated since this issue has been driving me crazy for the past three days.

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    and .html
    By default, php code is only parsed within .php files. Have you configured your web server so that it also parses php code in .html files? If not, you need to use .php files.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •