Php curl login with session and display respone/result on the next page

Good day i have written a code for login into a dashboard that works perfectly, my challenge is i want the when logged in i want the response to be displayed on the next page i.e dashboard see the code below.

$data = array(

    'EmailAddress' => '',

    'Password' => '1234567890',

    'SubscriberID' => '1b2b3h4g7s3t9f8s7w'


    $url = "login.php";

    $nextPage = "dashboard.php";

    $options = array(

    'http' => array(

        'method'  => 'POST',

        'content' => json_encode( $data ),

        'header'=>  "Content-Type: application/json\r\n" .

                    "Accept: application/json\r\n"



    $context  = stream_context_create( $options );

    $result = file_get_contents( $url, false, $context );

    $response = json_decode( $result, true );

    //echo $result; to see the result remove comment and add comment to header('Location: '.$nextPage);

    if ($response["Message"] !== "The request is invalid." && $response["Authenticated"]) {

        echo "login successfull";

        header('Location: '.$nextPage);

    } else {

        echo "login failed!";


Kindly help

What have you tried so far? I’d probably put the message in a session variable and then look for that in the dashboard code.

You’ll probably have trouble with that header redirect to dashboard.php because you’ve already sent output to the browser just before it. You should be seeing “headers already sent” errors unless you’ve enabled output buffering. If you have, echoing something immediately before a page redirect is a bit pointless.