<?php session_start(); 

 require_once("funcoes.php"); 

 if(isset($_POST['logando'])){	
      	$login	= mysql_real_escape_string(strip_tags(addslashes($_POST['login'])));
		$senha	= mysql_real_escape_string(strip_tags(addslashes($_POST['senha'])));
                $senha  = md5($senha);
                $senha  = md5($senha); 

				
				
				$select  = "SELECT * FROM tb_usuario WHERE login = '$login' AND senha = '$senha'";
		$query = mysql_query($select);
		echo mysql_error();
		if (mysql_num_rows($query) == 1) {
				$sql        = mysql_fetch_array($query);
                                $nome       	 = $sql['nome']; 
								$permissao       = $sql['permissao']; 
                                $chave      	 = "b4d10da0732fa25feb64100768b5604f";
				$ip         = $_SERVER["REMOTE_ADDR"];
                                
							
                                $chave      = md5($ip.$chave);                                
				$_SESSION['m4rseille']     = array("nome" => $nome, "chave" => $chave, "ip" => $ip, "permissao" => $permissao);
                                
				echo "<META HTTP-EQUIV='REFRESH' CONTENT='0; URL=painel.php'>";
				 echo "<script type='text/javascript'> window.location='painel.php' </script>";

			}
		else{
               
			echo "<META HTTP-EQUIV='REFRESH' CONTENT='0; URL=index.php'>";	
			echo "<script type='text/javascript'> window.location='index.php' </script>";
			}
        };
        
        if(isset($_GET['logout'])){
            if($_GET['logout'] == 1){
                
                unset($_SESSION['m4rseille']);

                 echo "<META HTTP-EQUIV='REFRESH' CONTENT='0; URL=index.php'>";
				 echo "<script type='text/javascript'> window.location='index.php' </script>";
						
			

            }
        } 