<?php

    //The fields and values to insert

  $user = array(
            'users_screen_name'=>$vars ->screen_name,
            'users_profile_image_url'=>$vars -> profile_image_url,
            'users_name'=>$vars->name,
            'users_statuses_count'=>$vars->statuses_count,
            'users_location'=>$vars->location,
            'users_description'=>$vars->description,
            'users_oauth_access_token'=>$access_token['oauth_token'],
            'users_oauth_access_token_secret'=>$access_token['oauth_token_secret']
        );

        // chek existing 
         $check_column = 'users_id';

         $exists = $database->exists( 'useres', $check_column,  array('users_screen_name' => $vars ->screen_name ));


        if (!$exists) {
            $add_query = $database -> insert('useres', $user);
            if ($add_query) {
                //update informations 


                    include 'get_user_info.php';


            }
            }
        else {

            $rs = "SELECT * FROM useres where users_screen_name ='".$vars ->screen_name."'";                        

            $user =  $database -> get_results($rs);
            // add the informations to the session 
            foreach ($user as $key => $value) {
                foreach ($value as $key => $value) {
                    $_SESSION[$key] = $value;
                }                           
            }
            //foreach ($_SESSION as $key => $value) {
                //echo $key ." = > ".$value."<br />";
            //}


            header ('location: user/dashboard.php');
            exit();
    }
    ?>

Recommended Answers

All 6 Replies

well this things dosen't work :

1- space before removed ?>
2- no hidden chars
3- opt codes dosen't work
4- .ini server file too

any other solutions ???

Is the error message saying headers are sent on line header ('location: user/dashboard.php'); or is the error being thrown from dashboard.php?

Usually I get that error when I session_start(); on the target file. If that is the case, you're probably calling session_start(); on both files and since there might be an include somewhere the session can't be started twice.

I'm just trying to guess here, since the code posted isn't enough for me to see where the error is.

If the case I mentioned is the problem you might want to wrap your session_start(); call with an headers_sent(); condition so it doesn't resend headers, like so:

    //if headers not sent
    if (!headers_sent()) {
        //start session
        session_start();
    }
    //continue with the logic since session will already exist

Hope this helps^^

Hi,

If you are getting error like "headers already sent" mens you are showing something before header('location: user/dashboard.php');

This may be a single space or any error. Also try to remove any blank space / balank lines before using header('location: user/dashboard.php');

If you need more help, Please let me know.
Thanks,
Ajay

Not on topic, but carefull with this also.

foreach ($user as $A_key => $A_value) {
    foreach ($value as $B_key => $B_value) {
        $_SESSION[$A_key] = $A_value;
    }                           
}

What I called $A_key and $A_value are accessible within the second loop... that might mess things up for you someday.

Thank you all Guys but the problem is changed !!!

1- first i tried this code at first ob_start(); and the error message disappear ??!! but this is not the end i got then this error >>

Warning: Invalid argument supplied for foreach() in /home/user/dashboard.php on line 39

now what ??!!

Usually that last error means that you're trying to loop through something other than an array. Try:

if(is_array($expectedArray)){
    foreach(....){
        //your code
    }
} else {
    //take care of the non-array variable
}

Keep in mind my previous post, since you might get that error in the sub-loop as well. Don't forget to echo or var_dump the objects you're putting into the foreach to make sure what they are.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.