SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru DenverDave's Avatar
    Join Date
    Feb 2001
    Location
    Denver, Colorado
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In an attempt to have some options for ColdFusion hosting, I am studying MySQL and PHP4. While my final host is UNIX, my development environment is Windows.

    I am currently working my way through the book "MySQL/PHP Database Applications" by Jay Greenspan. I thought it would be helpful to have others to study along with and discuss topics. I have other PHP4 books, but this one had several applications that I was interested in. If you are interested - please let me know.

    I am currently struggling with what I think are colliding variables from Cookies and Forms in the Survey application. I like many things about PHP4, but I sure miss ColdFusion's cookie.variable, form.variable, url.variable separation.

    Thanks - Dave

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I have just "discovered" sessions and they are truly better than cookies. Son pointed me in the direction of http://www.php.net/manual/en/ref.session.php

    Everyone in the PHP/MySQL forum is willing to help, so post any questions you have

  3. #3
    SitePoint Guru DenverDave's Avatar
    Join Date
    Feb 2001
    Location
    Denver, Colorado
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, here is an attempt. The situation is - there is an authentication script "win_authenticate.php" in the Survey Application of the book "MySQL/ PHP Database Applications" that intentionally uses Session variables and Form variables with the same name.
    -----------
    session_register("PHP_AUTH_USER");
    session_register("PHP_AUTH_PW");
    session_register("valid_user");
    -----------
    and then in the form later in the script:
    <form method=post>
    Username: <input type=text name="PHP_AUTH_USER" value="$PHP_AUTH_USER">
    <br>
    Password: <input type=text name="PHP_AUTH_PW" value="$PHP_AUTH_PW">
    <br>
    <input type=submit>
    </form>
    ---------------
    The first time through we get an ugly error message that the variables in the form do not exist but if the correct logon and passord are supplied, the user is validated. However, if an incorrect logon and password is supplied and the script is executed again, the session variables exist and there is not an error message, but the form will not work, because (I think) the session variables are used first.

    Does anyone have an idea or have worked through this example? Not that I would try to do this intentionally, but if there are Session, Cookie, URL, and Form variables with the same name passed to a PHP4 script - which one wins?

    Thanks - Dave

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On a login page like this, I usually run session_unset() after the form is submitted, this gets rid of all the current session data, that way the new data will get registered and the new values will be available to the session. I am doing a login script right now as we speak(I type). Here is bsically how I do it. On every password protected page i put
    PHP Code:
    session_start();
    if (
    $SESSION["username"] == ""header("Location: login.php"); 
    On login.php I use
    PHP Code:
    if ($submit) {
    session_unset();
    //run a query to db and authenticate user
    //if authenticated
    session_register("SESSION");
    $SESSION["username"] = $username;
    $SESSION["password"] = $password;
    header("Location: index.php");
    //Else
    //Print Error Message


    <form method=post>
    Username: <input type=text name="username" value="<? print $SESSION["username"]; ?>">
    <br>
    Password: <input type=text name="password" value="<? print $SESSION["password"]; ?>">
    <br>
    <input type=submit name=submit value=Submit>
    </form>



    Hope that helps
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •