SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34
  1. #26
    SitePoint Member
    Join Date
    Apr 2005
    Location
    East Anglia, England
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am new to php, where do i put this then?:

    full check_login.php file:

    PHP Code:
    <html>
    <head>
    <title>Untitled Document</title>
    </head>

    <body>
    <?php
    session_start
    ();
    /* check login script, included in db_connect.php. */



    if (!isset($_SESSION['username']) || !isset($_SESSION['password'])) {
        
    $logged_in 0;
        return;
    } else {

        
    // remember, $_SESSION['password'] will be encrypted.

        
    if(!get_magic_quotes_gpc()) {
            
    $_SESSION['username'] = addslashes($_SESSION['username']);
        }


        
    // addslashes to session username before using in a query.
        
    $pass $db_object->query("SELECT password FROM users WHERE username = '".$_SESSION['username']."'");

        if(
    DB::isError($pass) || $pass->numRows() != 1) {
            
    $logged_in 0;
            unset(
    $_SESSION['username']);
            unset(
    $_SESSION['password']);
            
    // kill incorrect session variables.
        
    }

        
    $db_pass $pass->fetchRow();

        
    // now we have encrypted pass from DB in 
        //$db_pass['password'], stripslashes() just incase:

        
    $db_pass['password'] = stripslashes($db_pass['password']);
        
    $_SESSION['password'] = stripslashes($_SESSION['password']);



        
    //compare:



        
    if($_SESSION['password'] == $db_pass['password']) { 
            
    // valid password for username
            
    $logged_in 1// they have correct info
                        // in session variables.
        
    } else {
            
    $logged_in 0;
            unset(
    $_SESSION['username']);
            unset(
    $_SESSION['password']);
            
    // kill incorrect session variables.
        
    }
    }


    // clean up
    unset($db_pass['password']);

    $_SESSION['username'] = stripslashes($_SESSION['username']);

    ?>
    </body>
    </html>
    Can you tell me where in the above file that needs to go?

    Sorry about this, I don't know much about PHP

  2. #27
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the top to
    PHP Code:
    <?php
    session_start
    (); 
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    </head>

    <body>
    YOu need to put session_start before any output to the browser.

  3. #28
    SitePoint Member
    Join Date
    Apr 2005
    Location
    East Anglia, England
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh I know what you mean now, sorry

    Now I get:

    Warning: Cannot send session cookie - headers already sent by (output started at c:\phpdev5\www\public\php stuff\register.php:9) in c:\phpdev5\www\public\php stuff\check_login.php on line 2

    Warning: Cannot send session cache limiter - headers already sent (output started at c:\phpdev5\www\public\php stuff\register.php:9) in c:\phpdev5\www\public\php stuff\check_login.php on line 2
    So many errors lol

  4. #29
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have anyting before the session_start();? Even whitespace?

  5. #30
    SitePoint Member
    Join Date
    Apr 2005
    Location
    East Anglia, England
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope no space at all

    PHP Code:
    <?php
    session_start
    ();
    ?> 
    <html>
    <head>
    <title>Untitled Document</title>
    </head>
    <body>

  6. #31
    SitePoint Member
    Join Date
    Apr 2005
    Location
    East Anglia, England
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ive fixed it! I added

    <?php
    session_start();
    ?>

    to the beginning of EVERY page

    Only error I get is once I have registered:

    Warning: Unknown modifier '/' in c:\phpdev5\www\public\php stuff\register.php on line 82
    line 82 of register.php:

    if ($_POST['website'] != '' & !preg_match("/^(http|ftp):///", $_POST['website'])) {

    How do i get rid of this error?

  7. #32
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like I said, that deals with regular expressions, which sadly I am not skilled in. I would start a new forum post for that issue, maybe someone will help you.

  8. #33
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:
    if ($_POST['website'] != '' & !preg_match("/^(http|ftp):\/\//", $_POST['website'])) {

  9. #34
    SitePoint Member
    Join Date
    Apr 2005
    Location
    East Anglia, England
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, thats got it


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
  •