SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Brasil
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session and session variables not working

    I have this code for the login.php:
    PHP Code:
    <?PHP
        session_start
    ();
        unset(
    $_SESSION['usuario']);
        unset(
    $_SESSION['senha']);
        
    session_destroy();
        if(isset(
    $_POST['submit'])){
            
    $usuario $_POST['usuario'];
            
    $senha $_POST['senha'];
            
    session_start();
            
    $_SESSION['usuario'] = $usuario;
            
    $_SESSION['senha'] = $senha;
            
    header('location: index.php');
        }
    ?>
    this goes before the form I made witch is:
    PHP Code:
    <form name="form1" method="post" action="<?PHP echo($PHP_SELF); ?>">
    <input name="usuario" type="text" class="caixa" id="usuario">
    <input name="senha" type="text" class="caixa" id="senha" maxlength="6">
    <input name="submit" type="submit" class="botao" value="Enviar">
    </form>
    then in each page of the admin I check if the user is logged:
    PHP Code:
    <?PHP
        session_start
    ();
        if(isset(
    $_SESSION['usuario']) || isset($_SESSION['senha'])){
            
    $usuariosql $_SESSION['usuario'];
            
    $senhasql $_SESSION['senha'];
            
    $dbcnx = @mysql_connect ('localhost''calesa''pass');
            
    mysql_select_db('calesa');
            
    $sqlprocura "SELECT * FROM Admin WHERE Usuario = '$usuariosql' AND Senha = '$senhasql' ";
            
    $query mysql_query($sqlprocura);
            
    $num mysql_num_rows($query);
            if(
    $num != "0"){
                
    header('location: index.php');
            }
            else{
                
    header('location: login.php');
            }
        }
        else{
            
    header('location: login.php');
        }
    ?>
    then in the logoff script I set:
    PHP Code:
    <?PHP
        session_start
    ();
        unset(
    $_SESSION['usuario']);
        unset(
    $_SESSION['senha']);
        
    session_destroy();
        
    header('location: ../index.php');
    ?>
    what is wrong cause it is not working and Iīm getting to think Iīm stupid cause I canīt understand php and I canīt make anything work.
    Thanks for the help.

  2. #2
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you able to login? What exactly is happening when you try?

    Also in the first block of code, try switching the variables that store the sessions around like this :
    PHP Code:
    $usuario $_SESSION['usuario'];
    $senha $_SESSION['senha']; 
    And then change the form's action value like this:
    PHP Code:
    <form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    And on the block of code for each page of the admin, take out the quotes from around the zero like this:
    PHP Code:
            if($num != 0){ 


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
  •