Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:50:59+00:00 2026-06-17T14:50:59+00:00

I have this code in login.php if ( $sth->execute() ) { $row = $sth->fetch(PDO::FETCH_ASSOC);

  • 0

I have this code in login.php

if ( $sth->execute() ) {
    $row = $sth->fetch(PDO::FETCH_ASSOC);
    if ( $row ) {
        var_dump($row); // See below
        $_SESSION['login'] = $row['login'];
        setcookie('login', $row['login'], time() * 7 * 24 * 60 * 60);
        if ( $row['right'] == ACCESS_ADMIN ) {
            echo "true"; // true
            $_SESSION['right'] = ACCESS_ADMIN;
            setcookie('right', $row['login'], time() * 7 * 24 * 60 * 60);
        }
    }
}


var_dump($row) - array(3) 
{ 
    ["login"]=> string(6) "phplox"
    ["password"]=> string(32) "827ccb0eea8a706c4c34a16891f84e7b"
    ["right"]=> string(5) "admin" 
} ?>
<br>

Ok, all right. Go to index.php.

<?php var_dump($_COOKIE) ?> `// array(1) { ["PHPSESSID"]=> string(26) "o05mr9luc2ok8ieadss4v9mhg0" }`

But if

<?php var_dump($_SESSION) ?> // 

the result is:

array(3) 
{
    ["request_token"]=> string(32) "335f1dcd4283889f0f2fe602cfa36d71"
    ["login"]=> string(6) "phplox" ["right"]=> string(5) "admin" 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:51:00+00:00Added an answer on June 17, 2026 at 2:51 pm

    You can’t send any output before setting cookies. Cookies are sent via a HTTP header and so they must be sent before any output has been sent to the browser. Here, you echo something, then try to set the cookie:

                echo "true"; // <--- REMOVE THIS
                $_SESSION['right'] = ACCESS_ADMIN;
                setcookie('right', $row['login'], time() + (7 * 24 * 60 * 60)); // add to the time, don't multiply time()
    

    You can also check the return value of setcookie(), which returns a boolean false if output has already been sent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code for displaying content for login and registration in my PHP
I have this in my PHP code, and it currently does the login request
I have this code in the login.php file : //save user data $token=$user->getId().'_'.hash('sha256',$user->getUsername().microtime()); $name='fsusr_'.$user->getUsername();
I have this code in JS: if($('.log input:checked')) { alert('login checked'); alert('do what you
I am trying to Login or SugarCrm using REST. I have this code,, //Login
I have this horribly stripped delphi code that basically login to server, save cookie
I have this regex code: RewriteCond %{REQUEST_URI} !/login([/]{0,1}) [NC] RewriteCond %{REQUEST_URI} !/search/([/]{0,1}) [NC] RewriteCond
I have this code. The code below is working in Firefox, but it is
I have this code: captcha.php: session_start(); class Captcha { protected $code; protected $width =
I have this code for a form <?php session_start(); ?> <!DOCTYPE html PUBLIC -//W3C//DTD

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.