Sessions are driving me to insanity

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Jay Salzman

    Sessions are driving me to insanity

    I'm writing a blogging app that uses an image file of a short string that
    users need to type in to comment. I've heard it called a "captcha" system.

    The problem is that the file that creates string and the image of the string
    can't access $_SESSION, and so has no way of passing the string to the
    receiving form.



    view_by_permali nk.php (Smarty template, actually):

    Verification String:
    <img src="captcha2.p hp?{$sessionNam e}={$sessionId} " />

    Enter the string in the image:
    <form action="add.com ment.php" method="post">
    <input type="text" name="userCaptc haInput" />
    </form>



    captcha2.php:

    // Create the string.
    (snip)

    // Define colors and create the image.
    (snip)

    imagestring ($image, 5, 1, 1, $cmntPass, $colorBlue);
    ImagePNG( $image );
    ImageDestroy( $image );

    session_id( $_REQUEST['PHPSESSID'] );
    start_session() ;
    $_SESSION['captcha'] = $cmntPass;



    add_comment.php :

    echo '<pre>'; print_r($_SESSI ON); echo '</pre>';
    echo '<pre>'; print_r($_POST) ; echo '</pre>';
    exit;




    The problem is that I haven't found a way to send the random string from
    captcha2.php to add_comment.php .

    I've tried and tried, but I can't seem to access $_SESSION variables in
    captcha2.php. I think sending the image somehow interfers with setting the
    session.

    How can I start a session and set up a session variable from captcha2.php?

    Thanks!
    Pete
  • Oli Filth

    #2
    Re: Sessions are driving me to insanity

    Peter Jay Salzman said the following on 17/12/2005 17:07:[color=blue]
    > I'm writing a blogging app that uses an image file of a short string that
    > users need to type in to comment. I've heard it called a "captcha" system.
    >
    > The problem is that the file that creates string and the image of the string
    > can't access $_SESSION, and so has no way of passing the string to the
    > receiving form.
    >
    >
    > captcha2.php:
    >
    > // Create the string.
    > (snip)
    >
    > // Define colors and create the image.
    > (snip)
    >
    > imagestring ($image, 5, 1, 1, $cmntPass, $colorBlue);
    > ImagePNG( $image );
    > ImageDestroy( $image );
    >
    > session_id( $_REQUEST['PHPSESSID'] );
    > start_session() ;
    > $_SESSION['captcha'] = $cmntPass;
    >[/color]

    Firstly, there is no function called start_session() , it's session_start() .

    Secondly, there must be *no* output from a script before session_start()
    is called.

    If you had had error_reporting set to E_ALL, you would already have
    spotted these mistakes... ;)


    --
    Oli

    Comment

    Working...