Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 19

Discussione: problema login

  1. #1

    problema login

    Aiutatemi ragazzi altrimenti lancio il computer dalla finestra
    Sto facendo delle prove per un form di login ma mi da un problema allora il form funziona metto l user e la pass e mi fa accede alla pagina ma se io metto l indirizzo per esteso compresa la èagina che dovrebbe essere protetta me la apre comunque allego un esempio su altervista
    http://provepa.altervista.org/ user prova pass abc e si apre http://provepa.altervista.org/prova.html
    ma se scrivo direttamente l'indirizzo http://provepa.altervista.org/prova.html me lo apre direttamente senza fare login
    vi allego gli script

    index.html

    <html>
    <title>
    </title>
    <style type="text/css">
    <!--
    body {
    background-color: #00FF66;
    }
    -->
    </style><head>



    <td align="center" valign="middle"><form action="controllo.php" method="post">
    <table width="280" border="0" cellpadding="0" cellspacing="0">
    <tr align="center" valign="middle">
    <td width="140" height="30" align="center"><div align="center">User : </div></td>
    <td width="149" height="30"><input name="user" type="text" id="user" size="15"></td>
    </tr>
    <tr align="center" valign="middle">
    <td height="30"><div align="center">Password : </div></td>
    <td height="30"><input name="password" type="password" id="password" size="15"></td>
    </tr>
    <tr align="center" valign="middle">
    <td height="30"><input type="submit" name="Submit" value="Login"></td>
    <td height="30" align="left"><input type="reset" name="Submit" value="Resetta"></td>
    </tr>
    </table>
    </form>
    </head>
    </html>

    controllo.php

    <?php
    $data=date("m.d.y, H:i:s");
    include('database.php');
    if(in_array($_POST['user'],$datauser)){
    $valuser= 1;
    $chiaveuser = array_search($_POST['user'], $datauser);
    }
    if(in_array($_POST['password'],$datapassword)){
    $valpassword= 1;
    $chiavepassword = array_search($_POST['password'], $datapassword);
    }
    $valsomm= $valuser+$valpassword;
    if(($valsomm==2)&&($chiavepassword==$chiaveuser)){
    //bisogna creare un file per ogni utente registrato ... il nome del file deve //essere uguale al nome dell'utente che deve accedere alla pagina propria.
    //ES. abc.php (per utente abc)
    //ES. def.php (per utente def)
    //e così via
    header("Location: $wwww.gazzetta.it");
    }else{
    //invece qui ci devi mettere la pagina a che da errore nell inserimento del login
    include('errore.html');
    }
    ?>

    database.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

    <?php
    //inserisci tra le parentesi i nomi utenti separati da virgola
    $datauser = array(prova, ciao, cellulare);
    //inserisci la password per ogni utente
    $datapassword = array(abc, def, ghi);
    ?>
    </head>


    <body>

    </body>
    </html>


    vi prego aiutatemi

  2. #2
    Devi creare una pagina tipo questa:
    Codice PHP:
    <?php
    session_start
    ();
    if(!isset(
    $_SESSION['nome_sessione'])){
    header("location:pagina.php");
    exit;
    }
    ?>
    E la devi mettere in ogni pagina che vuoi proteggere!

  3. #3
    Scusami non conosco bene il php anzi sono poco più di un novellino di questo limguaggio potresti dirmi come fare? allora creo una pagina con lo script che mi hai inviato e poi come lo collego agli altri script? potresti indicarmi la procedura?

  4. #4
    Il file lo chiami sessione.php

    E nelle pagine dove vuoi metterlo scrivi

    <?php include('sessione.php') ?>

  5. #5
    ti ringrazio provo subito sei stato gentilissimo

    se posso vorrei chiederti un ultimo favore
    se io volessi far aprire una pagina diversa per ogni utente cioè diciamo l utentye prova apre una pagina che gli altri non possono vedere l utente ciccio apre un altra pagina che gli altri non possono vedere ecc ecc


    ti ringrazio per la cortesia e la celerità

  6. #6
    Di niente!
    Per fare quello che hai chiesto penso dovresti far partire una sessione diversa quando fai partire il log in!

  7. #7
    <?php
    session_start();
    if(!isset($_SESSION['nome_sessione'])){
    header("locationagina.php");
    exit;
    }
    ?>

    allora ho creato il file sessione php dimmi se è giusto perchè non mi finziona

    <?php
    session_start();
    if(!isset($_SESSION['sessione.php'])){
    header("prova.html");
    exit;
    }
    ?>


    e poi nella pagina

    <?php
    include('sessione.php')

    ?>

    giusto?

  8. #8
    Non così:
    Codice PHP:
    if(!isset($_SESSION['sessione.php'])){ 
    Ma così:

    Codice PHP:
    if(!isset($_SESSION['nome_di_sessione_che_devi_impostare_quando_fai_il_login'])){ 
    Nella pagina per fare il log in,metti all'inizio del codice "session_start();" e poi quando verifichi che password e user siano corretti metti:

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

  9. #9
    Allora ho fatto come dici ma ho sbagliato sicuramente perchè non funziona

    ecco

    index.html
    <html>
    <title>
    </title>
    <style type="text/css">
    <!--
    body {
    background-color: #00FF66;
    }
    -->
    </style><head>
    <?php

    "session_start();"

    ?>


    <td align="center" valign="middle"><form action="controllo.php" method="post">
    <table width="280" border="0" cellpadding="0" cellspacing="0">
    <tr align="center" valign="middle">
    <td width="140" height="30" align="center"><div align="center">User : </div></td>
    <td width="149" height="30"><input name="user" type="text" id="user" size="15"></td>
    </tr>
    <tr align="center" valign="middle">
    <td height="30"><div align="center">Password : </div></td>
    <td height="30"><input name="password" type="password" id="password" size="15"></td>
    </tr>
    <tr align="center" valign="middle">
    <td height="30"><input type="submit" name="Submit" value="Login"></td>
    <td height="30" align="left"><input type="reset" name="Submit" value="Resetta"></td>
    </tr>
    </table>
    </form>
    </head>
    </html>

    controllo.php

    <?php
    $data=date("m.d.y, H:i:s");
    include('database.php');
    if(in_array($_POST['user'],$datauser)){
    $valuser= 1;
    $chiaveuser = array_search($_POST['user'], $datauser);
    }
    if(in_array($_POST['password'],$datapassword)){
    $valpassword= 1;
    $chiavepassword = array_search($_POST['password'], $datapassword);
    }
    $valsomm= $valuser+$valpassword;
    if(($valsomm==2)&&($chiavepassword==$chiaveuser))
    $_SESSION['user'] = $_POST['user'];



    {
    //bisogna creare un file per ogni utente registrato ... il nome del file deve //essere uguale al nome dell'utente che deve accedere alla pagina propria.
    //ES. abc.php (per utente abc)
    //ES. def.php (per utente def)
    //e così via
    header("Locationrova.html");
    }else{
    //invece qui ci devi mettere la pagina a che da errore nell inserimento del login
    include('errore.html');
    }
    ?>

    sessione.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <?php
    session_start();
    if(!isset($_SESSION['user'])){
    header("locationrova.html");
    exit;
    }
    ?>


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Documento senza titolo</title>
    </head>

    <body>
    </body>
    </html>

    prova.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <?php
    include('sessione.php')

    ?>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Documento senza titolo</title>
    <style type="text/css">
    body {
    background-color: #363;
    text-align:center;
    }
    </style>
    </head>

    <body>



    ecco ma non va se per favore mi correggi tu il codice te ne sarei infinitamente grato grazie ancora

  10. #10
    Utente di HTML.it L'avatar di brodik
    Registrato dal
    Jan 2009
    Messaggi
    764
    index.html
    Codice PHP:
    <html>
    <title>
    </title>
    <style type="text/css">
    <!--
    body {
    background-color: #00FF66;
    }
    -->
    </style><head>
    <?php

    "session_start();"

    ?>

    <td align="center" valign="middle"><form action="controllo.php" method="post">
    <table width="280" border="0" cellpadding="0" cellspacing="0">
    <tr align="center" valign="middle">
    <td width="140" height="30" align="center"><div align="center">[b]User : [/b]</div></td>
    <td width="149" height="30"><input name="user" type="text" id="user" size="15"></td>
    </tr>
    <tr align="center" valign="middle">
    <td height="30"><div align="center">[b]Password : [/b]</div></td>
    <td height="30"><input name="password" type="password" id="password" size="15"></td>
    </tr>
    <tr align="center" valign="middle">
    <td height="30"><input type="submit" name="Submit" value="Login"></td>
    <td height="30" align="left"><input type="reset" name="Submit" value="Resetta"></td>
    </tr>
    </table>
    </form>
    </head>
    </html>
    intanto se includi uno script php l'estensione del file deve essere php,
    seconda cosa
    codice:
    <?php  "session_start();"  ?>
    va senza " " e prima di ogni output

    sessione.php
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <?php
    session_start
    ();
    if(!isset(
    $_SESSION['user'])){
    header("location:prova.html");
    exit;
    }
    ?>


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Documento senza titolo</title>
    </head>

    <body>
    </body>
    </html>
    anche qui session_start() va prima di ogni output

    prova.html
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <?php
    include('sessione.php')

    ?>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Documento senza titolo</title>
    <style type="text/css">
    body {
    background-color: #363;
    text-align:center;
    }
    </style>
    </head>

    <body>
    se includi uno script php l'estensione del file deve essere php
    eXvision

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.