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

  • SEARCH
  • Home
  • 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 225553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:25:29+00:00 2026-05-11T19:25:29+00:00

Im very new in php and try to use cookie but it is not

  • 0

Im very new in php and try to use cookie but it is not woking in my site, can anyone guide me please , what is going wrong in my code:

<?php
session_start();
?>
<script>
function Redirect(url)
{
 location.href = url;
}

</script>
<?php 

define('_VALID_ACCESS', true);
include_once "includes/connect.php";
include_once "includes/login.php";


if(empty($_POST['loginname']) || empty($_POST['password']))
{
    $msg = "User or password is empty";
}
else
{
    if(login($_POST['loginname'], $_POST['password']) == true)
    {
        $usern = $_POST['loginname'];
        session_register('loginname');
        $loginname = $usern;        
        sleep(1);
            if(activestatus($_POST['loginname'], $_POST['password']) == true)
            {
            $usern = $_POST['loginname'];
            session_register('loginname');
            $loginname = $usern;        
            sleep(1);

            $hour = time() + 3600;
            setcookie("ID_my_site", $_POST['loginname'], $hour);
            setcookie("Key_my_site", $_POST['password'], $hour); 
            $test = $_COOKIE["ID_my_site"];
            $msg = "<script> Redirect ('home.html?testname=".$test."')</script>"; 
             //header("Location: home.html"); 
            }
            else
            {
            $msg = "<script> Redirect ('valid.php?testname=".$usern."')</script>"; 
            }

    }
    else
    {
        $msg = "<font color=red>User or Password is wrong</font>";
    }
}
echo '<div id="divTarget">' . $msg . '</div>'; 
?>
  <link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection">
  <link rel="stylesheet" href="css/blueprint/print.css" type="text/css" media="print">
  <link rel="stylesheet" href="css/blueprint/ie.css" type="text/css" media="screen, projection">  
 <body>
 <div class="container" id="login_container">
<form id="login" action="action.php" method="post" name="loginform" >
    <fieldset id="login_screen"  style="width:350px">
        <label id="login_label" for="login">User Login </label> 
        <br><br>
        <label for="login">Email Address</label>
        <input type="text" name="loginname" id="loginname" value="email@coolmates.com">    
        <p id="space"><label for="password">Password</label>
        <input type="password" id="password" name="password"  value="********" ></p>
        <input type="checkbox">Keep me signed in until i signout
        <p id="test"><input type="submit" value="Submit"></p>
        <a href="forgetpassword.html">Forgot
        your password</a>&nbsp;&nbsp;|<span id="free">Not a member?</span><a href="regForm.html">Sign up</a><blink><span id="free">Free</span></blink> 
        </p>
    </fieldset>
</form> </div>
</body>
  • 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-05-11T19:25:30+00:00Added an answer on May 11, 2026 at 7:25 pm

    Turn on display_errors and set your error_reporting to E_ALL and you should see an error message about ‘headers already sent’ – you have to call setcookie() BEFORE ANY HTML IS SENT. From php.net/setcookie:

    setcookie() defines a cookie to be
    sent along with the rest of the HTTP
    headers. Like other headers, cookies
    must be sent before any output from
    your script (this is a protocol
    restriction). This requires that you
    place calls to this function prior to
    any output, including and
    tags as well as any whitespace.

    In the code block that you posted this bit:

    <script>
    function Redirect(url)
    {
     location.href = url;
    }
    
    </script>
    

    Is being output directly to the browser well before you ever attempt to set the cookies.

    Your two possibilities would be to use output buffering so that you output everything at the very end or to switch to a method where all of your processing code is executed first in one script and there you set $_SESSION and cookie values and then include a second script at the tail end of the first that contains the code to be output to the browser.

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

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I'm writing an automation script on a production server that, among other things, needs
I have been programming in Python, PHP, Java and C for a couple or
What I'm trying to do is run the same SQL select on many Oracle
I'm planning to make a very simple program using php and mySQL. The main

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.