osSESSIONato!!!!!!!!!!!!!!!!!!!!!!

mailok

Nuovo Utente
1 Nov 2006
10
0
0
Ciao a tutti...

sto impazzendo con le sessioni...
il concetto teorico è molto banale ma non funzionano come dovrebbero ora vorrei capire il perchè...

------------------------------------------------------------


1)innanzitutto....session_start() inizia solo e sempre una nuova sessione o se ne esiste una carica anche i dati???

------------------------------------------------------------


2)Mettiamo che ho:

//protezione.php
//che includo in tutte le pagine esclusa la prima dove inizio la //sessione
<?php

if($_SESSION("login")!="LOGGED")
{
exit();

}
?>

//page1.php

<?php

session_start();
$_SESSION("login")="NOLOGGED";
..
...
...
....

//........arrivo ad un punto dove verifico che il login è corretto
//e setto quindi la variabile
$_SESSION("login")="LOGGED";

//da questo punto in poi finche' non chiudo il browser dovrei //accedere a tutte le pagine

?>


//pagina2.php

<?php
include("protezione.php");

...
.
.
.
....
//ora da qui passo a pagina3.php

?>


//pagina3.php

<?php
include("protezione.php");

...
.
.
.
....


?>

mi succede che le variabili di sessione vengono riconosciute solo dalla pagina1 alla 2 ..ed una sola volta..!(per esempio se da una paginak ridireziono a 2...dice _SESSION undefined!)

queste cose che non so risolvere seppur banali mi fanno capire che c'è qualcosa di losco che non ho capito sulle sessioni...
------------------------------------------------------------

3)L'altro problema è che non mi funziona redirect!!
quando faccio l'istruzione...

headers("location : prova.php");
mi si genera un Warning: headers already sent......... che è????
------------------------------------------------------------

SOMEBODY HELP ME

GRAZIE1000
 

polinet

Nuovo Utente
7 Mar 2004
18
0
0
WaterLand
www.polinet.biz
3)L'altro problema è che non mi funziona redirect!!
quando faccio l'istruzione...

headers("location : prova.php");
mi si genera un Warning: headers already sent......... che è????


controlla di non avere spazi tra lo script.
 

mailok

Nuovo Utente
1 Nov 2006
10
0
0
oumemì

T ringrazio ma sembra non essere quella la soluzione.... anche se non c'è piu' il warning...

ho provato a metterla come prima istruzione...
questa volta non ha nessun effetto :(
 

sassidesign

Utente Attivo
15 Lug 2005
172
1
0
38
Canosa (BA)
www.sassidesign.it
ciao,
devo dire che anche io in un primo momento ho avuto dei problemoni con le sessioni, poi dopo qualche ricerca per fortuna sono riuscito a sistemare tutto! :beer:

in pratica avevo anche io il tuo stesso problema, compreso quello del redirect.
per il problema del redirect l'ho risolto facendolo in javascript tramite l'istruzione echo di php: :cool:

PHP:
$url = $_SERVER['HTTP_REFERER'];
echo '<script>';
echo "  document.location.href = '".$url."'";
echo '</script>';

per quanto riguarda invece le sessioni in generale, ho scritto un articolo abbastanza lungo che sembra proprio fare al caso tuo...
lo trovi sul mio sito a questo indirizzo: http://www.comefaccio.net/tutorial/tutorial-leggi.php?id_tutorial=349 . prima di poterlo leggere però, dovrai registrarti al sito e fare il login. :fonzie:

mi scuso con i mod per il link verso il mio sito, ma non credo sia il caso di copiare qui quattro pagine di tutorial :D

fammi sapere se hai risolto! buon lavoro.
 

mailok

Nuovo Utente
1 Nov 2006
10
0
0
credo che sia un problema di configurazione del mio php.ini........

se a qualcuno di voi funzionano le sessioni...please mandatemi in discussione il php.ini

vediamo che posso fare...
 

mailok

Nuovo Utente
1 Nov 2006
10
0
0
Ho riportato il mio problema in uno script davvero molto base...
cio' nonostante non funziona ...

***index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>


<?php

session_start();
$_SESSION['prova']='ok';
include("pagina1.php");
?>


</body>
</html>

***protezione.php
<?php

session_start();

if(!isset($_SESSION['prova']))
{
echo("ACCESS DENIED");
exit;
}
else
{
echo("OK!");
}

?>

***pagina1.php

<?php

include("protezione.php");

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<input type="submit" name="Submit" value="Submit" src="pagina2.php">

<a href="pagina2.php">pagina</a>

</body>
</html>

***pagina2.php

<?php

include("protezione.php");

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
questa è la pagina 2
</body>
</html>

**php.ini solo la parte relativa alle session


[Session]
; Handler used to store/retrieve data.
session.save_handler = files

; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
session.save_path = "${path}\tmp\"

; Whether to use cookies.
session.use_cookies = 1

; This option enables administrators to make their users invulnerable to
; attacks which involve passing session ids in URLs; defaults to 0.
; session.use_only_cookies = 0

; Name of the session (used as cookie name).
session.name = PHPSESSID

; Initialize session on request startup.
session.auto_start = 0

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0

; The path for which the cookie is valid.
session.cookie_path = /

; The domain for which the cookie is valid.
session.cookie_domain =

; Handler used to serialize data. php is the standard serializer of PHP.
session.serialize_handler = php

; Define the probability that the 'garbage collection' process is started
; on every session initialization.
; The probability is calculated by using gc_probability/gc_divisor,
; e.g. 1/100 means there is a 1% chance that the GC process starts
; on each request.

session.gc_probability = 1
session.gc_divisor = 1000

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440

; PHP 4.2 and less have an undocumented feature/bug that allows you to
; to initialize a session variable in the global scope, albeit register_globals
; is disabled. PHP 4.3 and later will warn you, if this feature is used.
; You can disable the feature and the warning seperately. At this time,
; the warning is only displayed, if bug_compat_42 is enabled.

session.bug_compat_42 = 0
session.bug_compat_warn = 1

; Check HTTP Referer to invalidate externally stored URLs containing ids.
; HTTP_REFERER has to contain this substring for the session to be
; considered as valid.
session.referer_check =

; How many bytes to read from the file.
session.entropy_length = 0

; Specified here to create the session id.
session.entropy_file =

;session.entropy_length = 16

;session.entropy_file = /dev/urandom

; Set to {nocache,private,public,} to determine HTTP caching aspects.
; or leave this empty to avoid sending anti-caching headers.
session.cache_limiter = public

; Document expires after n minutes.
session.cache_expire = 180

; trans sid support is disabled by default.
; Use of trans sid may risk your users security.
; Use this option with caution.
; - User may send URL contains active session ID
; to other person via. email/irc/etc.
; - URL that contains active session ID may be stored
; in publically accessible computer.
; - User may access your site with the same session ID
; always using URL stored in browser's history or bookmarks.
session.use_trans_sid = 0

; The URL rewriter will look for URLs in a defined set of HTML tags.
; form/fieldset are special; if you include them here, the rewriter will
; add a hidden <input> field with the info which is otherwise appended
; to URLs. If you want XHTML conformity, remove the form entry.
; Note that all valid entries require a "=", even if no value follows.
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"




help.piu'infrettapossible :)