Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 09-12-2006, 11:38 PM   #1 (permalink)
Registered User
 
Join Date: Aug 2006
Posts: 23
OS: Windows XP?


PHP, cookies, signing in

So I was trying to work on a very simple sign in script for my site, so they can either sign in as a teacher or student, and it checks the appropriate password, and sets a cookie. Having some problem though. I keep getting this message whenever I try to set the cookie(Line 255 is the line the setcookie is on):

Warning: Cannot modify header information - headers already sent by (output started at urlstuffhere/index.php:6) in urlstuffhere/index.php on line 255

PHP Code:
      <?php
        $user 
$_POST["user"]    ;
        
$password $_POST["password"]    ;
        
$year 60 60 24 365 time(); 

        switch (
$user) {
          case 
teacher:
            if (
$password=="********") {
              
setcookie(user,Teacher,$year);
            }
            break;
          case 
student:
            if (
$password=="********") {
              
setcookie(user,Student,$year);
            }
            break;
          default:
        }

        if (isset(
$_COOKIE["user"]    )) {
          echo 
"You are signed in as a " $_COOKIE["user"]     . ", click here to sign out.";
        } else {
          echo 
"<form action='index.php' method='post'>";
          echo 
"<select name='user'>";
          echo 
"<option></option>";
          echo 
"<option value='teacher'>Teacher</option>";
          echo 
"<option value='student'>Student</option>";
          echo 
"</select>";
          echo 
"<input type='password' name='password' />";
          echo 
"<input type='submit' value='Sign in' />";
          echo 
"</form>";
        }

      
?>

Last edited by Dustyshouri; 09-12-2006 at 11:39 PM.
Dustyshouri is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 09-13-2006, 01:34 AM   #2 (permalink)
Registered User
 
Join Date: Aug 2006
Posts: 23
OS: Windows XP?


Okay, scratch that bit. I fixed that problem, didn't know the cookie script had to be set before the html tag... anyways, still having problems. It's just not setting the cookie at all. It won't give an error, I've even taken scripts directly from tutorial sites and tried them and they aren't working. I don't have cookies blocked either.
Dustyshouri is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-13-2006, 06:29 AM   #3 (permalink)
Retired
 
gamerman0203's Avatar
 
Join Date: Oct 2005
Location: Grand Rapids, MI
Posts: 2,144
OS: XP MCE, Ubuntu Gutsy

My System

I'm not much of a PHP buy, more ASP than anything, but I'm going to take a shot in the dark:

where you're setting your cookie, you don't have the "$" before "user". It seems to me that when calling a variable, you need to call it how it is set. But I don't know anything about php so forgive me if I'm wrong.
gamerman0203 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-13-2006, 02:56 PM   #4 (permalink)
Design Team
 
DJ-Zep's Avatar
 
Join Date: Mar 2006
Location: Philadelphia
Posts: 1,541
OS: Windows Vista Home Premium (x64)

My System

Please post the source code for index.php so that I can find out exactly what is going wrong.
__________________
Nice music blog

Nvu || Notepad++ || Apache || PHP || Keep TSF Alive

"The great thing about a computer notebook is that no matter how much you stuff into it, it doesn't get bigger or heavier."
DJ-Zep is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 06:18 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85