0

So I have this form that asks for user and password:

    <?php
    $emmagatzemarSessions="/u/alum/u1920477/public_html/tmp";
    ini_set('session.save_path',$emmagatzemarSessions);
    session_start();
    include 'vars.php'; 
?>
<html>
<h1>Identificacio</h1>
<h3>Introdueix el teu usuari i contrasenya per entrar a oracle</h3>
<hr>
<form action="menu.php" method="post">

    Usuari: 
    <input  type="text" 
            name="user" />
    Contrasenya: 
    <input 
            type="password" 
            name="pass" />

<input type="submit"/>
</form>
<hr>
<?php   

    $_SESSION["user"] = $_POST["user"];
    $_SESSION["pass"] = $_POST["pass"];
?>
</html>

However, in the next file, 'menu.php' it says I couldn't acces the database. The user and password I'm inserting are correct. Here is the code to connect that I'm using:

    #!/usr/bin/php-cgi
<?php
    $emmagatzemarSessions="/u/alum/u1920477/public_html/tmp";
    ini_set('session.save_path',$emmagatzemarSessions);
    session_start();
    include 'vars.php'; 

    $conn = oci_connect($_SESSION["user"], $_SESSION["pass"], 'oracleps');

    echo("username is: " . $_SESSION["user"]);
    if (!$conn) { 
    echo "<p>No hem pogut connectar amb la BD.</p>";

?>
<html>
        <br><br><br>
        <div id="tornar">
            <li><a href="index.php">Tornar a l'inici</a></li>
        </div>
<?php 
    die;
    }
?>
<head>
<title>Menú empresa</title>
</head>
<body>
<div id="menu">
  <h1>Menú</h1>
</div>
<div id="alta">
  <ul>
    <li><a href="alta.html">Donar d'alta un client</a></li>

    <li><a href="consulta.php">Consultar vehicles disponibles</a></li>

    <li><a href="llogar.html">Llogar un vehicle</a></li>

    <li><a href="retorn.html">Retornar un vehicle llogat</a></li>

    <li><a href="revisio.php">Veure revisions</a></li>
  </ul>
</div>
        <br><br><br>
        <div id="tornar">
            <li><a href="index.php">Tornar a l'inici</a></li>
        </div>
</body>
</html>

I have looked for similar questions, asked my collegues who are doing the same thing but I can't find out why this isn't working! It would be amazing if I could get some help from you guys! Thanks a lot.

Edited with the full code of both files. Ignore the 4 first lines. I hope you guys can help me because I have no clue what I'm doing wrong!

4

2 に答える 2

2

このコード行は、セッションを追跡するすべての php ページの上部にある必要があります。

session_start();

次のように、変数が実際にフォームから送信されているかどうかも常に確認する必要があります。

if(isset($_SESSION['username']))
{
   // do something
}

データベースに接続するためのロジックが正しいと確信している場合は、フォームから受け取ったデータをログに記録して、それが正しいかどうかを確認する必要があります。

error_log("username is: " . $_POST["username"]);
于 2013-01-03T12:57:13.333 に答える