0

I used to store all my data in 000webhost, today I decided to move to hostinger. So.. after moving it I replaced the old mysql_connect info by the new one. Alright, after doing that I tested it, everything has ran fine, except some echo functions.

check file (connects to the server and do the login):

    <?php

    $servidorr = "mysql.XXXX.co.uk";
    $bdd = "XXXXXXXX";
    $usuarioo = "XXXXX";
    $senhaa = "XXXXXXX";


    if (!empty($_POST) AND (empty($_POST['usuario']) OR empty($_POST['senha']))) {
        header("Location: geton"); exit;
    }


    mysql_connect($servidorr, $usuarioo, $senhaa) or trigger_error(mysql_error());

    mysql_select_db($bdd) or trigger_error(mysql_error());

    $usuario = mysql_real_escape_string($_POST['usuario']);
    $senha = mysql_real_escape_string($_POST['senha']);
    $lang = mysql_real_escape_string($_POST['lang']);


    $sql = "SELECT `id`, `nome`, `nivel` FROM `usuarios` WHERE (`usuario` = '". $usuario ."') AND (`senha` = '". sha1($senha) ."') AND (`ativo` = 1) LIMIT 1";
    $updatelang = "UPDATE usuarios SET lang='$lang' WHERE usuario='$usuario'";
    $query = mysql_query($sql);
    if (mysql_num_rows($query) != 1) {

        echo "<script>alert('Oops! Looks like there is something wrong with your login! *perhaps a typo or you did not fill out the fields*'); location.href='geton'</script>"; exit;
    } else {

        $resultado = mysql_fetch_assoc($query);
      mysql_query($updatelang);


        if (!isset($_SESSION)) session_start();

        $_SESSION['UsuarioID'] = $resultado['id'];
        $_SESSION['UsuarioNome'] = $resultado['nome'];
      $_SESSION['usuario'] = $resultado['usuario'];
        $_SESSION['UsuarioNivel'] = $resultado['nivel'];
      $_SESSION['lang'] = $resultado['lang'];

        header("Location: http://mapmaking.zz.mu/pages/home"); exit;
    }

    ?>


Home file (these echos are just for testing and this is not the original file, the original one has the same php stuff, except the echo functions, those are in random lines):

<?php


if (!isset($_SESSION)) session_start();

  $tlang = $_SESSION['UsuarioLang'];
  $aclevel = $_SESSION['UsuarioNivel'];
  $nick = $_SESSION['UsuarioNome'];

$neededal = 1;
if (!isset($_SESSION['UsuarioID']) OR ($_SESSION['UsuarioNivel'] < $neededal)) {
    session_destroy();
    header("Location: http://inside.mapmaking.uk.to/geton"); exit;


}

session_start();

echo $tlang;
echo $aclevel;
echo $nick;
echo "$level$tlang$tlang";


?>

[this one basically start the session and check if the connected user acess level is 1]

Echo $tlang does not work! :( somehow it doesn’t, I have no idea why ;_;

Hope you guys help me, thank you!!

4

2 回答 2

0

$_SESSION['lang'] != $_SESSION['UsuarioLang']

您为第一个赋值,但期望第二个赋值。

$_SESSION['lang'] = $resultado['lang'];

$tlang = $_SESSION['UsuarioLang'];

于 2013-08-14T21:46:08.747 回答
-1

更改此行:

$_SESSION['lang'] = $resultado['lang'];

到以下:

$_SESSION['UsuarioLang'] = $resultado['lang'];

session_start()你也应该在没有isset支票的情况下打电话。此外,您应该考虑使用&&而不是AND||代替OR,因为 PHP 有奇怪的运算符优先级规则(赋值比or=具有更高的优先级)。ANDOR

于 2013-08-14T21:47:37.277 回答