A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Recalling Session Variables throughout site

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    27

    resolved [RESOLVED] Recalling Session Variables throughout site

    Hey

    I cannot seem to recall my session variables throughout my site and i cannot see where i am going wrong.

    I have variables in my flash file which i have posted into my 'info.php' all working fine, i declare the post variables in 'info.php' with the following:

    Code:
    $num = $_POST['number'];
    	$choice = $_POST['choice'];
    	$colour = $_POST['colour'];
    These variables then get called in a simple form that is echo'd as below:

    Code:
    echo '<div id="info">
        <form name="form" method="post" action="">
        <table width="450" border="0" cellspacing="1" cellpadding="3">
        <tr><td width="65%"><strong>Number</strong></td>
        <td width="65%"><strong>Choice</strong></td>
        <td width="20%"><strong>Colour</strong></td>
        <td width="15%"><strong>Quantity</strong></td></tr>
        <tr><td>'.$num.'</td><td>'.$choice.'</td><td><input type="text" name="colour" value="'.$colour.'"readonly></td>
        <td><input type="text" name="qty1" size="5" value="1"> </td></tr>
        <tr valign="bottom"><td><br>Paying with: <br>
        <input type="radio" name="x" value="CashPayment" checked="checked">Cash<br>
        <input type="radio" name="x" value="CardPayment">Card</td>
        <input type="submit" name="Submit" value="Submit"></td></tr>
        </table>
        </form>';
    I then set the post variables to session variables with the following:

    Code:
    $num = $_POST['number'];
    	$choice = $_POST['choice'];
    	$colour = $_POST['colour'];
            $_SESSION['num'] = $_POST['number'];
    	$_SESSION['choice'] = $_POST['choice'];
    	$_SESSION['colour'] = $_POST['colour'];
    So the form has the session variables stated as in:

    Code:
    echo '<div id="info">
        <form name="form" method="post" action="">
        <table width="450" border="0" cellspacing="1" cellpadding="3">
        <tr><td width="65%"><strong>Number</strong></td>
        <td width="65%"><strong>Choice</strong></td>
        <td width="20%"><strong>Colour</strong></td>
        <td width="15%"><strong>Quantity</strong></td></tr>
        <tr><td>'. $_SESSION['num'].'</td><td>'. $_SESSION['choice'].'</td><td><input type="text" name="colour" value="'. $_SESSION['colour'].'"readonly></td>
        <td><input type="text" name="qty1" size="5" value="1"> </td></tr>
        <tr valign="bottom"><td><br>Paying with: <br>
        <input type="radio" name="x" value="CashPayment" checked="checked">Cash<br>
        <input type="radio" name="x" value="CardPayment">Card</td>
        <input type="submit" name="Submit" value="Submit"></td></tr>
        </table>
        </form>';
    I have
    Code:
    <?php
    session_start();
    At the top of every php page.

    Can anyone help me with what i am doing wrong? The variables display when you first go to 'info.php' but as soon as you navigate away and then back the fields are empty.

    Any ideas?

    Many thanks

    Jon

  2. #2
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    There could be a couple of things, I don't know how you're calling your PHP code, but if you're using AMFPHP of another remoting package, those can sometimes interfere with sessions and make them useless. Also, you can't output anything on the page prior to the session_start() call. But you sound like you know that.

    Have you tried testing the scripts with a regular HTML form, outside of flash, just to see if the PHP can record the session data properly under those conditions?

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    27
    The problem was that i was telling php that the session variable was the result of the posted data, so when i went back to info.php without posted anything, they became 0, got it with this code from the help off another forum:

    Code:
    <?php
    session_start();
    
    if(isset($_POST['number']) && !empty($_POST['number'])) {
        $_SESSION['num'] = $_POST['number'];
    }
    
    echo $_SESSION['num'];
    ?>

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

HTML5 Development Center