Jump to content


Photo

can someone help me with setcoockies ?


  • Please log in to reply
10 replies to this topic

Poll: would someone please correct my setcookie codes? (0 member(s) have cast votes)

would someone please correct my setcookie codes?

  1. could someone help me? (0 votes [0.00%])

    Percentage of vote: 0.00%

  2. coupld someone re-do my code for me? (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#1 bretx

bretx
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 29 July 2006 - 11:00 PM

could someone help me please i keep getting header errors, and here they are..
[quote]Warning: Cannot modify header information - headers already sent by (output started at /home/rowly/public_html/bretx-designs/login.php:1) in /home/rowly/public_html/bretx-designs/login.php on line 192

Warning: Cannot modify header information - headers already sent by (output started at /home/rowly/public_html/bretx-designs/login.php:1) in /home/rowly/public_html/bretx-designs/login.php on line 193
Thank You! You will be redirected [/quote]

your help would be most appreciated. my php snippet is below.. thank you..

[quote]
<?
oB_start();
// allows you to use cookies.
include("config.php");
if (!$logged[username])
{
if (!$_POST[login])
{
echo("

<center>

<form method=\"post\">

<b>username;</b> <input type=\"text\" name=\"username\" style=\"border: 1px solid adc3ce; font-family: tahoma; font-size: 8pt; color= black; background-color: transparent\"><br>

<b>password;</b> <input type=\"password\" name=\"password\" style=\"border: 1px solid adc3ce; font-family: tahoma; font-size: 8pt; color= black; background-color: transparent\"><br>

<input type=\"submit\" value=\"   login   \" name=\"login\" style=\"border: 1px solid adc3ce; font-family: tahoma; font-size: 8pt; color= black; background-color: transparent\">

</form>



</center>");
}
if ($_POST[login]) {
// the form has been submitted. We continue...
$username=$_POST['username'];
$password = md5($_POST[password]);
// the above lines set variables with the submitted information.
$info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($info);
if($data[password] != $password) {
// the password was not the user's password!
echo "Incorrect username or password!";
}else{
// the password was right!
$query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$user = mysql_fetch_array($query);
// gets the user's information
setcookie("id", $user[id], time()+3600);  /* expire in 1 hour */
setcookie("pass", $user[password], time()+3600, "/~rasmus/", ".bretx-designs.x1topsites.com", 1);

// the above lines set 2 cookies. 1 with the user's id and another with his/her password.
echo ("Thank You! You will be
redirected");
// modify the above line...add in your site url instead of yoursite.com
}
}
}
else
{
// we now display the user controls.
echo ("
Welcome $logged[username]


- <a href=\"editprofile.php\">Edit Profile

- <a href=\"members.php\">Member List

- <a href=\"logout.php\">Logout");
}
?>


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 July 2006 - 11:00 AM

Try this:
<?php

include("config.php");

if (!isset($logged['username']))
{
    if (!isset($_POST['login']))
    {
        echo <<<HTML
<center>
<form method="post">
username: <input type="text" name="username" style="border: 1px solid adc3ce; font-family: tahoma; font-size: 8pt; color= black; background-color: transparent">
password: <input type="password" name="password" style="border: 1px solid adc3ce; font-family: tahoma; font-size: 8pt; color= black; background-color: transparent">
<input type="submit" value="   login   " name="login" style="border: 1px solid adc3ce; font-family: tahoma; font-size: 8pt; color= black; background-color: transparent">
</form>
</center>
HTML;
    }
    elseif (isset($_POST['login']))
    {
        // the form has been submitted. We continue...
        $username=$_POST['username'];
        $password = md5($_POST['password']);

        // the above lines set variables with the submitted information.
        $info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
        $data = mysql_fetch_array($info);

        if($data['password'] != $password)
        {
            // the password was not the user's password!
            echo "Incorrect username or password!";
        }
        else
        {
            // the password was right!
            $query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
            $user = mysql_fetch_array($query);
            // gets the user's information
            setcookie("id", $user['id'], time()+3600);  /* expire in 1 hour */
            setcookie("pass", $user['password'], time()+3600, "/~rasmus/", ".bretx-designs.x1topsites.com", 1);

            // the above lines set 2 cookies. 1 with the user's id and another with his/her password.
            echo ("Thank You! You will be redirected");

            // modify the above line...add in your site url instead of yoursite.com
        }
    }
}
else
{
    // we now display the user controls.
    echo <<<HTML
Welcome {$logged['username']}
- <a href="editprofile.php">Edit Profile</a>
- <a href="members.php">Member List</a>
- <a href="logout.php">Logout</a>
HTML;
}
?>


#3 bretx

bretx
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 30 July 2006 - 11:12 PM

no sorry that didnt help any, thank you for trying to help me anyways i appreciate it..
i still get this warning..

Warning: Cannot modify header information - headers already sent by (output started at /home/rowly/public_html/bretx-designs/login.php:1) in /home/rowly/public_html/bretx-designs/login.php on line 190

Warning: Cannot modify header information - headers already sent by (output started at /home/rowly/public_html/bretx-designs/login.php:1) in /home/rowly/public_html/bretx-designs/login.php on line 191



#4 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 30 July 2006 - 11:16 PM

Didja read this post:
http://www.phpfreaks...ic,37442.0.html
??

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#5 bretx

bretx
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 30 July 2006 - 11:18 PM

no i didn't very sorry. thank you for notifying me

#6 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 30 July 2006 - 11:21 PM

It's all good, just make sure to check the stickies first (they're there for a reason, ;))

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#7 bretx

bretx
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 30 July 2006 - 11:22 PM

i still dont get it though, this is retarded, i have no idea what to do, i havent been on the net in months, and i forgot how to do everything i knew before, and now i just cant remember..

#8 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 30 July 2006 - 11:32 PM

Note: ob_start(): This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

#9 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 30 July 2006 - 11:45 PM

^ the buffer has a size limit and is not recommended. Instead you should learn how to do it correctly without them.

Firstly, I can't remember how to use cookies. I've always used sessions. They're not only more secure...but they're better. :) It's easy to switch from cookies to sessions, so if ya want to do that I can help you there. :)

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#10 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 30 July 2006 - 11:47 PM

A combination of both can also work well :)

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 31 July 2006 - 09:08 AM

Is there any whitespace before the opening <?php tag in login.php. Also is there any whitespace before <?php and after ?> in config.php

As you have some form of output which causeing this error. Also how are you saving your PHP files? Make sure you saving them with ANSI encoding, if you are saving them with other type of enconding such as UTF-8 it causes this problem.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users