0
<?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();
    }
    ?>

Edited by Dani: Formatting fixed

3
Contributors
6
Replies
49
Views
3 Years
Discussion Span
Last Post by Fernando_4
0

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 ???

0

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^^

0

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

0

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.

0

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 ??!!

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.