Jump to content

A bit complexed question about cookies being deleted before the output starts


KubeR
Go to solution Solved by mac_gyver,

Recommended Posts

Hi,

Hm,I've been trying to do this in many different ways,but I never came into solution.

The problem is that I have two pages,one for login second for MySQL check and redirection back to the index page.

now,I have Private SSL installed and I set the redirection in .htaccess to redirect from http to https.

when the user types in the login id & password,then being redirected to the login check page and then quickly back to the index,I create a cookie which holds the result from the MySQL(small,just plain numbers) and I want to delete it once he reaches the index.php.

Now,the problem is that it doesn't delete the cookie and at the same time outputs this warnning:

Warning: Cannot modify header information - headers already sent by (output started at /home3/kirill/public_html/index.php:1) in /home3/kirill/public_html/cdel.php on line 5

(I created a file named "cdel.php" for it to load in different file before the output & extrenal output buffer(ob_start),both(together & seperated) didn't work and gave the same warning and I didn't step forward to the solution)

 

So,I ask to help me a bit with it(?),as I am just out of idea's and not familiar yet with all PHP features & solutions/problems.

 

 

Before the hand,thank you.

KubeR.

Link to comment
Share on other sites

Yes,but as I already said,I tried this already.

The code is located before anything even starts,in a seperated file,included in the file using the "include" function and has an OB in it.

This is the code in case maybe it's needed or maybe if the problem is in my code :

(these are lines 1 & 2)

<? include("cdel.php");
if(!isset($_COOKIE["i"])) {?>

cdel.php:

<?
ob_start();
function delCookie($name) { 
        unset($_COOKIE[$name]); 
        return setcookie($name, NULL, -1); 
    } 
if(isset($_COOKIE["1"])) { 
$failed1=$_COOKIE["1"]; 
delCookie("1");
} 
if(isset($_COOKIE["2"])) { 
$failed2=$_COOKIE["2"]; 
delCookie("2");
}
ob_end_flush();
?>

I did try the solutions above,but yet,same problem apears.

Edited by KubeR
Link to comment
Share on other sites

In order to pin down what might be causing the output on line 1 of your index.php file, only put the php opening tag on line 1, with no other php statements on line 1

 

by also putting the include statement on line 1, you cannot tell if something before the opening php tag is causing the output or if something in the include file is causing the output.

 

and get rid of the output buffering statements. you should only use them when you WANT to buffer output, not to try to fix problems in your code, and in this case there's nothing in the body of your code that is even producing output, so they had no effect.

Link to comment
Share on other sites

I cut it to the first line as I thought maybe the line was the problem,however I tried to find the problem by deleting the https:// redirection in .htaccess and lowering the php tag by one line and the warning came from the opening tag and not from the first line which was empty.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.