PHP login......! help

Discussion in 'PHP' started by strgraphics, Jun 16, 2010.

  1. #1
    i have 3, files

    1. check.html
    2. index.php
    3. pro.php

    check.html having...

    
    
    <form action="index.php" method="post">
    
    Password:  
    <input type="password" name="pass"> 
    <input type="submit" value="submit">
    
    </form>
    
    PHP:
    index.php having...

    
    
    <?php
    
    session_start();
    
    if(!isset($_session['pass']))
    {
    $_SESSION['pass'] = $_POST['pass'];
    }
    
    $a="siva";
    $b=$_SESSION['pass'];
    if($a==$b)
    {
    
    Content..!
    
    }
    ?>
    
    PHP:
    3. pro.php

    
    
    <?php
    
    session_start();
    $a="siva";
    $b=$_SESSION['pass'];
    if($a == $b)
    {
    
    content
    
    }
    
    
    PHP:
    every thing working fine ..., but once i loged on.. if i click index.php, link the session is distroying....!

    what's wrong in index.php

    i mean if i click on check button it's showing index.php file successfully but if i click on index.php (<a href="index.php">) the sesstion again taking $_SESSION['pass'] = $_POST['pass'];

    any solution please
     
    strgraphics, Jun 16, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    Not sure what you are trying to do there but the problem is probably that you have $_SESSION in the if condition in lowercase in the index.php
     
    stephan2307, Jun 16, 2010 IP
  3. tommykent1210

    tommykent1210 Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What exactly are you trying to acheive with
    $_SESSION['pass'] = $_POST['pass'];
    PHP:
     
    tommykent1210, Jun 16, 2010 IP
  4. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    login page...., creating..
    form in check.html, once user click on submit button, it will post the value to index.php....,

    now my question is am i write correct code in index.php,


    $_SESSION['pass'] = $_POST['pass'];

    i am sending post pass to session pass..,
     
    strgraphics, Jun 16, 2010 IP
  5. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #5
    if(!isset($_session['pass']))
    {
    $_SESSION['pass'] = $_POST['pass'];
    }
    PHP:
    So, you assign $_POST['pass'] to $_SESSION['pass'] only if $_SESSION['pass'] is already set? I think you should do this:

    <?php 
    define('PASSWORD', 'yourPass');      // Put the password on the second quote.
    
    session_start()
    if (!isset($_SESSION['pass'])) {
      
      // Only do this stuff if the password is submitted
      if (isset($_POST['pass'])) {
        if ($_POST['pass'] == PASSWORD) {
          $_SESSION['pass'] = $_POST['pass'];
          header("Location: index.php");
          exit;
        } else {
          // Error handling goes here. 
        }
      }
    
      // If the password was not submitted, then print out the form.
      include('check.html');
      exit;
    }
    
    // Check the password in $_SESSION.
    if ($_SESSION['pass'] != PASSWORD) {
      exit;
    }
    
    ?>
    
    >>>> stuff goes here <<<<
    PHP:
    It wasn't tested, but I'm sure you can debug it. Just an idea of the sort of thing you need to do.
     
    Cozmic, Jun 16, 2010 IP
  6. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Ohh thanks friend.., i will try this.
     
    strgraphics, Jun 17, 2010 IP
  7. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #7
    You are wrong there. he is assigning $_POST['pass'] to $_SESSION['pass'] only if $_SESSION['pass'] is NOT yet set. Do you see the ! ? that means NOT.

    Also as I mentioned before SESSION should be upper case in this line

    if(!isset($_session['pass']))
    PHP:
     
    stephan2307, Jun 17, 2010 IP
  8. Scripts man

    Scripts man Guest

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Scripts man, Jun 17, 2010 IP
  9. dabaR

    dabaR Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I don't think anyone clearly told you yet.... $_SESSION and $_session are not the same. You need $_SESSION there.
     
    dabaR, Jun 17, 2010 IP
  10. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #10
    What are you on about??? Have you read the thread? I have mentioned it twice!!

     
    stephan2307, Jun 17, 2010 IP
  11. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #11
    ya i used $_SESSION .., friend., thanks yar... thanks to alllllll i got through...

    Thanks a lot... to alllll
     
    strgraphics, Jun 17, 2010 IP
  12. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #12
    I see. I missed the exclamation point.
     
    Cozmic, Jun 17, 2010 IP
  13. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #13
    Ya i am assigning $_POST['pass'] to $_SESSION['pass'] only if $_SESSION['pass'] is NOT yet set, whats wrong... there! first time it will assigning the post password to session password..,

    once it will set.....! the $_SESSION['pass'], pass variable for that session is ready..! and will work upto i unset it.

    i dont think its wrong...! guys what do you say.....!

    i mean if second time the page loads...!

    
    <?php
    
    session_start();
    
    $a="siva";
    $b=$_SESSION['pass'];
    if($a==$b)
    {
    
    Content..!
    
    }
    ?>
    
    PHP:
     
    strgraphics, Jun 17, 2010 IP