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 6374497
In Process

The Archive Base Latest Questions

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

My script is fairly simple. When someone tries to login, PHP checks the form

  • 0

My script is fairly simple. When someone tries to login, PHP checks the form data against a MySQL database, set’s a cookie for the session, and refreshes the page. Now, I’ve pinpointed the cookie script to be causing chaos and completely stopping the thing from working. However, I don’t know why. The code I am using is this:

<?php
header('Content-type: text/javascript');
$erroron="false";
$id='false';

$con = mysql_connect("localhost","***","***");
if (!$con)
  {
  die('$("#connecterror").stop().hide().fadeIn(); ');
  }

mysql_select_db("***", $con);

$result = mysql_query("SELECT * FROM users");

while($row = mysql_fetch_array($result))
  {

  if( $row['username']==$_POST["user"]&&$row['password']==$_POST["pass"])
{
if($row['confirmed']==1){
$id=$row['id'];
}
else{
echo '$("#erroractivate").stop(false,true).hide().fadeIn(200);';
}
 }
else if( $row['email']==$_POST["user"]&&$row['password']==$_POST["pass"])
{
if($row['confirmed']==1){
$id=$row['id'];
}
else{
echo '$("#erroractivate").stop(false,true).hide().fadeIn(200);';
}
 }
else{
if($erroron=="false"){
$erroron="true";
 echo '$("#error").stop(false,true).hide().fadeIn(200);';
}
}
  }
if($id=='false'){
 echo '$("#error").stop(false,true).hide().fadeIn(200);';
}
else{
echo '$("#page").text("You have logged in, redirecting...");$("body").css("cursor","wait");setTimeout("location.reload(true);",2000);';
setcookie("sessionid", $id,0,'/','profile.campatet.com',false,true);
}

mysql_close($con);

?>

Now, this the the part that is not working:

setcookie("sessionid", $id,0,'/','profile.campatet.com',false,true);

If I take that off, the script successfully refreshes the page, but because there is no cookie set, you can’t login. If I keep it on, it simply does nothing.

  • 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-25T01:29:45+00:00Added an answer on May 25, 2026 at 1:29 am

    PHP’s setcookie does it’s thing via the headers, and unless you use output buffering, echoing before attempting setcookie will send the headers prematurely and prevent the cookie from being set.

    http://php.net/manual/en/function.setcookie.php

    http://www.php.net/manual/en/intro.outcontrol.php

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

Sidebar

Related Questions

My problem in fairly simple. I have a login system constructed using php, mysql
I'm building a fairly simple PHP script that will need to send some emails
I'm writing a fairly simple register php script that uses PHP's built in mail()
As the title suggests, I've inherited a php/MySQL application which has fairly well written
I've written a fairly simple script that will take elements (in this case, <p>
I have a fairly simple Psake build script (default.ps1) that calls Invoke-Psake from within
I'm trying to rewrite a fairly simple MATLAB script in Haskell. I'm looking for
I have a fairly simple bash script that does some grep to find all
I have a fairly simple order creation form on a back office app I'm
I'm trying to create a PHP script which pulls xml data (text and images)

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.