I can't save session as array

Discussion in 'PHP' started by Tom12361, Aug 13, 2008.

Thread Status:
Not open for further replies.
  1. #1
    I can't save session $_SESSION["kokiai"] as array.
    And I can't use $_SESSION["kokiai"] on other page, what is the problem? What I need to add? Thanks for the answers.
    Btw, here is a code:

    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Pasirinkite prekes:<br />
    <select name="products[]" multiple="multiple" size="3">
    <option value="ferrari">ferrari</option>
    <option>audi</option>
    </select><p>
    <input type="submit" value="Claim it" />
    </form>
    </html>
    </body>
    <?php
    session_start();
    if (isset($_POST["products"])){
    $_SESSION["kokiai"] = serialize($_POST["products"]);
    echo "<br>Your products was registered";
    } else {
    echo "<br>You haven't chosen any products yet.";
    }
    ?><br>
    <A href="la.php"> See what you chose</A>
    PHP:
     
    Tom12361, Aug 13, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    session_start() must go at the top. Before sending ANYTHING (except other headers) to the user's browser. No white spaces, no HTML... nothing.

    And don't use $_SERVER['PHP_SELF'] like that. It allows XSS attacks.
     
    nico_swd, Aug 13, 2008 IP
Thread Status:
Not open for further replies.