#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    setcookie("username",$username,time()+14400,"/",".georgiaoffroad.com",0);

    That's how I set a cookie, and once a cookie is set I can access the 'username' cookie variable anywhere on the site (since I have a / in the path field).

    setcookie has to be used before any other header info is passed to the browser, else I get "too much info.." or somesuch error.

    With my current login script, I check to see if $username and $password exist (with a query to a users table). If so, I display the page content. If not, the user is prompted to enter a username & password.

    When the user presses 'go', the page is reloaded and php tests the un & pw again.

    I can check for user/pw at the top of every page, but what good is that if I can't at some point create a cookie with inputted data from a form? This is probably something incredibly simple, but I've been reading about setcookie on various sites and in a couple books for the last couple hours and everythings becoming a blur.

    Thanks for any help you can offfer
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    14
    If I am understanding your question correctly you are asking about grabbing the contents of a form and using in a setcookie()? You can do this as long as you don't try to output or send a header first before attempting to use the setcookie() function.

    You can check your login and then if it's good check the form results and then setcookie() using any of the results of those form. The key is to make sure you don't try to print anything or have any HTML or multiple <? ?> code parse tags or you'll get that error message.

    I get the feeling though as I am writing that maybe i'm missing what you are saying here. If you can post a bit of the code that isn't working, i bet myself or somebody else can help ya

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    Can I use an "IP address" instead of "www.url.com" in the setcookie function?

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    Ok, I think I have a working login/authentication routine.

    The following code is placed at the top of all of my 'secure' pages. (To answer my own last question, IP's work fine in the SETCOOKIE function.)

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?

    if(isset($username) and isset($username)) {
    require ("connect.inc.php3");
    $resultuserpw = mysql_query("SELECT id FROM users WHERE username='$username' AND password='$password'",$db);
    $userpwtest = mysql_numrows($resultuserpw);
    if ($userpwtest == 1) {

    // set a cookie and continue
    setcookie ("username",$username,time()+14400,"/","208.32.175.22",0);
    setcookie ("password",$password,time()+14400,"/","208.32.175.22",0);

    // check value of $action, from login form. if 'addnew', go to the Add New Model page,
    // otherwise continue here.
    if ($action =='addnew') {
    Header("Location: x_admininsert.php3");
    }

    } else {

    // username/pw failed, return to login.php3. the check variable tells login.php3 whether
    // or not to print 'login failed, try again' or the default 'enter user/pw'
    Header("Location: login.php3?check=authenticate");

    }

    ?>

    [/code]

    Thanks for the help. I was blitzed last night and didn't see the obvious... I had to have a seperate login page (before I had the login script and protected content in the same php page).

    - Mike

Similar Threads

  1. quick mysql/php question
    By mirthika in forum PHP Development
    Replies: 2
    Last Post: February 16th, 2004, 02:15 PM
  2. Quick regex wildcard question.
    By s200 in forum PHP Development
    Replies: 2
    Last Post: February 12th, 2004, 09:09 AM
  3. quick question
    By hingis_rules in forum Photoshop Help
    Replies: 1
    Last Post: January 27th, 2004, 09:40 PM
  4. quick question about folders
    By Pompiuses in forum PHP Development
    Replies: 1
    Last Post: January 15th, 2004, 06:30 AM
  5. quick question
    By muratisik in forum HTML Programming
    Replies: 7
    Last Post: December 4th, 2003, 07:59 AM

IMN logo majestic logo threadwatch logo seochat tools logo