Computer problems,Computer help
*AX SOFT>>>Programming & Design

Php session issues?


This is my first time using sessions, and I think I'm using them wrong. I had a page executing fine with normal variables which retrieved user submitted post data, but, I had to convert those into session variables so peoples information got assigned UIDs and didn't get mixed up. However, when I ran the page with the session variables, it didn't execute, it was just blank. I've looked over my code, and I don't see any syntax errors, so i guess I have a fundamental problem with using session variables. Below is some code which I think has problems, so, please in your answer, tell me what you think is wrong, and some common restrictions of session variables.

below, I converted a $set1 variable into a session variable, receiving the data, i don't know if this is correct.
$_SESSION['set1'] = $_POST['set1'] ;

I'm not sure if this is correct either...
if ($_SESSION['set1'] == $getvalue1)...

I strung these together, not sure if this can work
$_SESSION['cumulative'] = $_SESSION['score1'] + $_SESSION['score2'] ;

or this...
$_SESSION['score'] = ($_SESSION['cumulative'] / $divisor)*100 ;

thanks for your input :)

First, check your web server logs for error. Make sure php error reporting is on. Whenever you get a blank page, you've got an error.

Are you calling session_start(); at the top of each of your files? Presuming you have a form that is posting 'set1' to the file in which you are setting the session variable, your syntax seems to be okay...

Edit: If you have server access, the apache logs are usually someplace like /usr/local/apache/logs. If you stick a file containing the following code in your webroot, it will tell you where logs, config files, etc. reside -

<?php
phpinfo();
?>

Also, try putting error_reporting(E_ALL); at the top of your php files. It should cause errors to go to the browser.

http://us2.php.net/error_reporting

If all else fails, go with brute-force - add a few echo statements through your code to see how far it's getting before it bails out.

One problem you are having is that if you have not enabled session autostarts in your php.ini file, you must call session_start() at the very top of any page on which you intend to use server variables.

http://us3.php.net/manual/en/function.se...
http://us3.php.net/manual/en/ref.session...

You can assign superglobals back and forth as you have above:

$_SESSION['set1'] = $_POST['set1'] ; // this is fine

You can also assign any local variable to the session superglobal, as below:

$foo = "bar";
$_SESSION['foobar'] = $foo;
echo $_SESSION['foobar']; //prints "bar"

Session variables can hold objects and primitive data types (strings / numbers / booleans, etc.), unless you are using session autostarts, in which case a session can only contain primitives.

As such, if your session variable contains a primitive, you can work with the primative as you would a local variable, including doing math on them.

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • RefactorIT refactoring Java Source Code?

    Refactoring code is something a human should do using an IDE. One analysis tool I enjoy is PMD. It runs a bunch of (configurable and extendable) rules and reports a list of things it sees. Sev...

  • How do i get a FONT like this in this image?

    Here is the website to download that font. ...

  • What is the font IMVU used for their logo?

    Baubau and Pico White are in that style. ...

  • How can I re-install windows vista again?

    pop that Vista disc in the cd tray and reboot..keep tapping the F2 key untill the black and white screen appears,now select install windows....windows will ask you if you want to keep the old parti...

  • Could you pls help me about html??

    i'm also has that same problem..

    ...
  • Hey!!!Are you a programmer ?? Can you help me to explain this Program in C-language? (below)? please !!?

    Here's the explanation: ------------------------- #include <stdio.h> ------------------------- This line tells us to INCLUDE a header file containing standard input output function...

  • I really need your help to assist me to sort out the errors i get on my program!?

    That is going to be quite difficult. If you are still stuck with your project assignment may be you can contact a programming expert live at website like ...

  • Jsp if statement question?

    You should the checking at database. E.g. Select ID from users where username ='uname' and password = 'password'; If the query return no result, means the username and pass...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster