Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    Sessioni senza Cookie:HELP!

    Ho un problema nella gestione di sessioni senza cookie:
    Devo ricevere i dati da un modulo di login (login,pwd) che vengono passati allo script tramite post assieme ad un campo hidden che mi da l'id di sessione:
    codice:
    <input type=hidden name=PHPSESSID value=$PHPSESSID>
    .
    Il mio problema sta nel fatto che lo script seguente, siccome una volta ricevuto il session id ricarica la pagina si dimentica delle variabili passate con post. Come posso aggirare il problema?
    codice:
    <?php
    
    if(IsSet($_POST['PHPSESSID']) && !IsSet($_COOKIE['PHPSESSID'])){
    	$PHPSESSID=$_POST['PHPSESSID'];
    	header("Location: http://localhost/inserimento/index.php?PHPSESSID=$PHPSESSID");
    }
    
    session_start();
    
    //Controllo username e password da login
    $login_r=$_POST['login'];
    $pwd_r=$_POST['pwd'];
    
    $conn_string="host=localhost dbname=autorized_users user=searcher password=***";
    //connessione al database degli utenti autorizzati
    $conn=pg_connect($conn_string) or die("ERRORE DI CONNESSIONE");
    //query di verifica
    $query="SELECT pwduser FROM usr_table WHERE username='$login_r'";
    $result=pg_query($conn,$query);
    $pwd_true=pg_fetch_row($result);
    if(strcmp($$_POST['pwd'],$pwd_true[0])==0){
    	$_SESSION['logged_in']=TRUE;
    	$_SESSION['user']=$_POST['login'];
    }
    
    
    //logout
    if($_GET['logout']==1){
    	$_SESSION=array();
    	session_destroy();
    	header("Location: http://localhost/inserimento/index.php");
    	exit;
    }
    
    ?>
    <!doctype html public "-//W3C//DTD html 4.0 //en">
    <html>
    
    <head>
    <title>xxx</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="generator" content="HAPedit 3.1">
    <link rel="stylesheet" type="text/css" href="../style.css">
    </head>
    <body>
    
    <?php
    
    $PHPSESSID=session_id();
    
    if(!IsSet($_SESSION['user'])){
    	
    	//Pagina di login
    	require "login.html";
    }
    else {
    	require "index_ins.php";
    }
    
    ?>
    </body>
    </html>
    Spero che qualcuno voglia aiutarmi...
    Ringrazio in anticipo!
    Max
    max

    Silence is better than bullshit.
    @mmarcon
    jHERE, Maps made easy

  2. #2
    <input type=hidden name=PHPSESSID value=$_GET['PHPSESSID']>
    ma se c'e' un session_start() il get ti arriva in automatico ...
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  3. #3

    Mmm...

    Non ho ben compreso:
    in pratica cosa devo cambiare nel mio codice?
    Scusa la mia ignoranza...
    max

    Silence is better than bullshit.
    @mmarcon
    jHERE, Maps made easy

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    613
    fa così, prima di ricaricare la pagine salvi le varibili $_POST in $_SESSION

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

    mi pare di aver capito che è questo che ti serve no?!

    Ricorda però che prima devi aprire la sessione

  5. #5
    Grazie mille Leandro!
    Adesso provo
    max

    Silence is better than bullshit.
    @mmarcon
    jHERE, Maps made easy

  6. #6

    Scusate ancora...

    Ma io posso fare una cosa del genere?
    codice:
    <?php
    
    if(IsSet($_POST['PHPSESSID']) && !IsSet($_COOKIE['PHPSESSID'])){
    	$PHPSESSID=$_POST['PHPSESSID'];
    	session_start();
    	$_SESSION['posted_login']=$_POST['login'];
    	$_SESSION['posted_pwd']=$_POST['pwd'];
    	header("Location: http://localhost/inserimento/index.php?PHPSESSID=$PHPSESSID");
    }
    
    session_start();
    
    //Controllo username e password da login
    $login_r=$_SESSION['posted_login'];
    $pwd_r=$_SESSION['posted_pwd'];
    $conn_string="host=localhost dbname=autorized_users user=searcher password=***";
    //connessione al database degli utenti autorizzati
    $conn=pg_connect($conn_string) or die("ERRORE DI CONNESSIONE");
    //query di verifica
    $query="SELECT pwduser FROM usr_table WHERE username='$login_r'";
    $result=pg_query($conn,$query);
    $pwd_true=pg_fetch_row($result);
    
    if(strcmp($$_POST['pwd'],$pwd_true[0])==0){
    	$_SESSION['logged_in']=TRUE;
    	$_SESSION['user']=$login_r;
    }
    //Il problema sembra essere che $login_r non viene mai assegnato a $_SESSION['user']
    //Puo' essere che sia causato dal fatto che ho due session_start anche su uno sta dentro un if? 
    
    //logout
    if($_GET['logout']==1){
    	$_SESSION=array();
    	session_destroy();
    	header("Location: http://localhost/inserimento/index.php");
    	exit;
    }
    
    ?>
    <!doctype html public "-//W3C//DTD html 4.0 //en">
    <html>
    
    <head>
    <title>---</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="generator" content="HAPedit 3.1">
    <link rel="stylesheet" type="text/css" href="../style.css">
    </head>
    <body>
    
    <?php
    
    $PHPSESSID=session_id();
    
    if(!IsSet($_SESSION['user'])){
    	
    	//Pagina di login
    	require "login.html";
    }
    
    else {
    	require "index_ins.php";
    }
    
    ?>
    </body>
    </html>
    Nel senso che non mi trovo mai a soddisfare la condizione per cui caricare index_ins.php...
    max

    Silence is better than bullshit.
    @mmarcon
    jHERE, Maps made easy

  7. #7
    A parte che c'era un errore in
    codice:
    $$_POST['pwd']
    che ho sostituito con
    codice:
    $pwd_r
    , ma la cosa continua a non funzionare: se i cookie sono attivi e sbaglio la password la prima volta poi non riesco piu' ad accedere...qualche idea??
    max

    Silence is better than bullshit.
    @mmarcon
    jHERE, Maps made easy

  8. #8
    Il problema sembra stare proprio nel cookie che mi memorizza login e password sbagliate la prima volta, e poi sembra non sovrascriverli piu'. Posso eliminare completamente i cookie, anche quelli di sessione?
    max

    Silence is better than bullshit.
    @mmarcon
    jHERE, Maps made easy

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 © 2025 vBulletin Solutions, Inc. All rights reserved.