Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP Sessions

  • 09-01-2011 1: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: 648 ✭✭✭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