2

I have the following registration.php file:

<?php 
include_once("QueryNew.php"); 

if (!get_magic_quotes_gpc()) {

$email=addslashes($_POST["email"]);
$password=addslashes($_POST["password"]);
$confirmpassword=addslashes($_POST["confirmpassword"]);
$uid=uniqid();

}

if (trim($email," ") == "" || trim($password," ") == "" && trim($confirmpassword," ") == ""){
    echo "<script type='text/javascript'>window.location='logintips.php?regErr=All fields are mandatory'</script>";
}

if (trim($password," ") != trim($confirmpassword," ")){
    echo "<script type='text/javascript'>window.location='logintips.php?regErr=Passwords didnot match'</script>";
}

if (trim($email," ") != "" || trim($password," ") != "" && trim($confirmpassword," ") != ""){

        $insertQuery = "INSERT INTO user VALUES('".$uid."','".$email."','".$password."','',1,".CURRENT_TIMESTAMP.")";
        $qry = new QueryNew();
        $insert = $qry->executeSelect($insertQuery);

        $SELECT_STAR = "select uid, email, timezone from ";

        $selectQuery = $SELECT_STAR . "user" . " where email = '".$email."'";

        $qry = new QueryNew();
        $select = $qry->executeSelect($selectQuery);

        while($row = mysql_fetch_assoc($select)) {
            $uidS = $row['uid'];
            $emailS = $row['email'];
        }

**//store $uidS and $emailS in a session variable and redirect to a (home) page**

}
?>

Once I am done with the insert and select queries, I want to create a session and redirect to someother page..

I tried session_start() as below:

        session_start();
        $_SESSION[uid] = $uidS;
        $_SESSION[email] = $emailS;

        echo $_SESSION[uid];
        echo $_SESSION[email];

Which gives an error:

**Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\website\try\MAIN\HOME\QueryNew.php:43) in C:\xampp\htdocs\website\try\MAIN\HOME\register.php on line 45**

If there is a better way than the above, please suggest.

Jason
  • 15,017
  • 23
  • 85
  • 116
Kannan Lg
  • 911
  • 4
  • 11
  • 21

4 Answers4

1

Read your error message.

QueryNew.php is generating some output (at line 43). You should not echo or print anything before you start your session. You could start the session before you include QueryNew.php though.

bummzack
  • 5,805
  • 1
  • 26
  • 45
0
 ob_start();

------------------
-----------
-------

ob_end_flush() ;
Pradeep Singh
  • 3,582
  • 3
  • 29
  • 42
  • thanks.. but is there a way to "create a session with the db values and redirect to someother page (say home page)" – Kannan Lg Dec 30 '11 at 05:50
  • i checked that question.. there is only one tag in my complete file! – Kannan Lg Dec 30 '11 at 06:05
  • You can do this by calling ob_start() and ob_end_flush() in your script, or setting the output_buffering configuration directive on in your php.ini or server configuration files. – Pradeep Singh Dec 30 '11 at 06:08
  • A good design won't need output buffers, if you come to using OB then you should consider a redesign of your architecture! – Paul Dec 30 '11 at 12:02
0
<?php ob_start();
if(session_id()){
//Session is already started
}else{
session_start();
}
?>
Mohit Bumb
  • 2,466
  • 5
  • 33
  • 52
0

Just put ob_start() in top of the page will resolve this error

Vijayan
  • 1,015
  • 2
  • 9
  • 12