Results 1 to 4 of 4

Thread: show example of session code

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    58

    show example of session code

    i m new in using session.

    can anyone show me an example of session code? like for example, when the user has entered their information in the fields and when they click onto the submit button, they will be redirected to the next page-with all their information being displayed.

    can anyone show me the example of the code?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: show example of session code

    <?

    session_start();
    session_register("MyVariableName");
    $MyVariableName = 8329;

    ?>

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: show example of session code

    Mendhak, your code has become obsolete. One should use the $_SESSION array now:
    PHP Code:
    <?php
        session_start
    ();

        if (isset(
    $_POST['submit'])) {
            
    $_SESSION['sessionVar'] = $_POST['sessionVar'];
        }

    ?>
    <html>
        <body>
            <?php if (isset($_SESSION['sessionVar'])): ?>
            <p>You entered <?php echo(htmlspecialchars($_SESSION['sessionVar'])) ?></p>
            <?php else : ?>
            <form method="post">
                <input type="text" name="sessionVar" />
                <input type="Submit" name="submit" />
            </form>
            <?php endif; ?>
        </body>
    </html>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: show example of session code

    On a slight tangent, when you handle a POST request you should silently redirect to the intended eventual location using a 303 redirection status code. This instructs the user agent not to cache the response and avoid the irritating "This page contains POSTDATA that has expired from cache" message if you try to go back or refresh the page.

Posting Permissions

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



Click Here to Expand Forum to Full Width