Results 1 to 9 of 9

Thread: PHP -

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User zombie13's Avatar
    Join Date: Oct:2012
    Location: Bulgaria - Ruse
    Posts: 63

    PHP -

    login.php
    PHP Code:
    if ($row mysql_fetch_array($q)) 
    {
        if(
    $rememberme == "on"){
            
    setcookie("username",$row['username'],time()+7200);
        }else if(
    $rememberme == "undefined"){
            
    $_SESSION['username'] = $row["username"]; 
        }
        
    header ("Location: ".$_POST['curPage']);

    index.php

    PHP Code:
    if(isset($_SESSION['username'])) {  // Block 1
                
    echo '<div id="lognat"><ul><li></li>,<li><a href="login/members.php">'$_SESSION['username'].'</a></li></ul>';
                echo 
    '<p><a href="login/logout.php"></a></p></div>';
                
            }
            
            else if(isset(
    $_COOKIE['username'])) {  // Block 2
                
    echo '<div id="lognat"><ul><li></li>,<li><a href="login/members.php">'$_COOKIE['username'].'</a></li></ul>';
                echo 
    '<p><a href="login/logout.php"></a></p></div>';
                
            }
            else if(isset(
    $_SESSION['error'])){ // Block 3
                
    echo $_SESSION['error'];
                
    session_destroy() ;
                require_once(
    'form.php');
            }
                   else{ 
    // Block 4
                
    require_once('form.php');
            } 
    , setcookie , , Block 4
    , , Block 1 .
    - , Block 2 Block 4.
    , .

  2. #2
    Registered User
    Join Date: Dec:2003
    Posts: 2,817
    . $_SESSION['error']? 99% 1 2? $rememberme ( , register_globals e on)?
    Gigabyte DS3P, E4400@9x333, 2x2Gb Super T@1000Mhz, Gigabyte GTX460OC 768Mb

  3. #3
    Registered User zombie13's Avatar
    Join Date: Oct:2012
    Location: Bulgaria - Ruse
    Posts: 63
    $_SESSION['error'] ,
    1 , 2 .
    $rememberme -
    register_globals

    - ,
    . , 2 4

  4. #4
    Registered User
    Join Date: Jul:2005
    Location: Sofiq
    Posts: 2,798
    setcookie . setcookie . .

  5. #5
    Registered User zombie13's Avatar
    Join Date: Oct:2012
    Location: Bulgaria - Ruse
    Posts: 63
    login.php
    PHP Code:
    <?php
    session_start
    ();
    require (
    "dbConfig.php");

    $username addslashes($_POST['username']);
    $password $_POST['password'];
    if(isset(
    $_POST['rememberme'])){
        
    $rememberme $_POST['rememberme'];
    }else{
        
    $rememberme "undefined";
    }


    if(!empty (
    $password))
    {
    $password md5(addslashes($password));
    }

    if(
    $_SERVER['REQUEST_METHOD'] != 'POST'header('Location:../index.php');

    $q mysql_query("SELECT username, password FROM users where username = '$username' AND password = '$password' Limit 1"); //  


    if ($row mysql_fetch_array($q)) {
        if(
    $rememberme == "on"){
            
    setcookie("username",$row['username'],time()+7200);
        }else if(
    $rememberme == "undefined"){
            
    $_SESSION['username'] = $row["username"]; 
        }
        
    header ("Location: ".$_POST['curPage']);
    }else{
        if (empty(
    $username)){
        
    $_SESSION['error'] ='<div class="mistake"> </div>';
        
    header ("Location:".$_POST['curPage']);
        }
        else if (empty(
    $password)){
        
    $_SESSION['error'] = '<div class="mistake"> </div>';
        
    header ("Location:".$_POST['curPage']);
        }
        else{
            
    $_SESSION['error'] = '<div class="mistake"> </div>';
            
    header("Location: ".$_POST['curPage']);
        }
    }


    ?>

    -

  6. #6
    Registered User
    Join Date: Jul:2005
    Location: Sofiq
    Posts: 2,798
    . , localhost 127.0.0.1. domain.

    php.net setcookie.

    something that wasn't made clear to me here and totally confused me for a while was that domain names must contain at least two dots (.), hence 'localhost' is invalid and the browser will refuse to set the cookie! instead for localhost you should use false.

    to make your code work on both localhost and a proper domain, you can do this:

    <?php

    $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
    setcookie('cookiename', 'data', time()+60*60*24*365, '/', $domain, false);

    ?>

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |