Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP Sessions

  • 09-01-2011 02:51PM
    #1
    Registered Users, Registered Users 2 Posts: 6,889 ✭✭✭


    Hi there,

    I'm a relatively experienced coder, but not in PHP!

    Basically, there is a section of the site I'm working on at the moment that requires that a) the user is not colourblind and b) that their screen is displaying colours reasonably accurately.

    I have a mysql database of the classic colour blindness tests (the dots with a number in them) stored with an image_id, a filename, and a correct(which is the correct response.
    <?php
    
    include('mysql.php');
    
    $query="SELECT * FROM blindness ORDER BY RAND() LIMIT 0,3";
    $result = @mysql_query($query);
    
    while($row = mysql_fetch_object($result)) {
    	$images[] = (object) $row;
    }
    
    session_start();
    
    $_SESSION['file1']=$images[0]->correct;
    $_SESSION['file2']=$images[1]->correct;
    $_SESSION['file3']=$images[2]->correct;
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Colour Test</title>
    </head>
    
    <body>
    <form action="cb-eval.php" method="get" name="cb">
    <table border="0">
      <tr>
        <td valign="top" class="image"><img src="<?=$images[0]->filename?>" width="144" height="135" /></td>
        <td valign="top" class="image"><img src="<?=$images[1]->filename?>" width="144" height="135" /></td>
        <td valign="top" class="image"><img src="<?=$images[2]->filename?>" width="144" height="135" /></td>
      </tr>
      <tr>
        <td><center><input name="img1" type="text" /></center></td>
        <td><center><input name="img2" type="text" /></center></td>
        <td><center><input name="img3" type="text" /></center></td>
      </tr>
      <tr>
        <td></td>
        <td><center><input name="submit" type="submit" value="Go!" /></center></td>
        <td></td>
      </tr>
    </table>
    </form>
    </body>
    </html>
    

    I worked out from cb-eval that the values I'm putting into the $_SESSION variables aren't being received. Basically, I want to compare file1 to img1(etc.) in cb-eval.php

    Any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 668 ✭✭✭Freddio


    session_start(); ....

    ... should be the first line of code in every php file that is calling or setting session variables.

    Also are you sure they are being populated in the first place ?


  • Registered Users, Registered Users 2 Posts: 6,889 ✭✭✭tolosenc


    Yeah, moving the session_start(); to the beginning was it. Cheers!


Advertisement