SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form, Form Processing, Cookie Setting :: In one file?

    Currently I have one .php file where there's a form if $_POST['formsubmit'] isn't set. If $_POST['formsubmit'] is set, the file processes the form instead. That's working flawlessly but now I've a complication. What I need to do is set two cookies.

    What happens is a user enters his username and password in the form and then the form gets processed (the form's action is PHP_SELF) and if the username and password are approved, what I need is to set cookies, one with the username and one with the password.

    How can I do this within the same file? I'm not sure how to work this but I know that I can't just set the cookies after the form has been processed and the username and password have been approved, because the headers have already been sent.

    Please advise what I could do here, I really appreciate all the help

  2. #2
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the form POSTs to itself, then a new page will have loaded -- the form won't be displayed: you will be checking the username and password.

    Where are the headers sent?

    A simple, yet not resource friendly solution is to call ob_start to buffer the output until the end of the script, but there shouldn't be any reason why you can't find the source of the header problem. Simply make sure nothing is outputted from the page the form POSTs to

    Cheers!
    My name is Steve, and I'm a super-villian.

  3. #3
    SitePoint Member industry's Avatar
    Join Date
    Aug 2003
    Location
    CHINA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The form's action is $PHP_SELF,but it still works like in different file and the header never been sent.

  4. #4
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've decided that I'll have the form's action as another file, have all the cookies set and the sql processing done in that file then header redirect back to the original file, so the cookies that have been set will be active too.

  5. #5
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by industry
    The form's action is $PHP_SELF,but it still works like in different file and the header never been sent.
    Exactly -- for example:

    PHP Code:
    if (isset($_POST['submit']) {
       
    //Authenticate user
       //Set Cookies
    } else {
       
    //Output form

    If the form is posted to PHP_SELF, the above code won't generate any headers until the cookies statement.
    My name is Steve, and I'm a super-villian.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •