Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 9570

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>session_set_save_handler</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Funções de manpulação de Sessões"
HREF="ref.session.html"><LINK
REL="PREVIOUS"
TITLE="session_set_cookie_params"
HREF="function.session-set-cookie-params.html"><LINK
REL="NEXT"
TITLE="session_start"
HREF="function.session-start.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual do PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.session-set-cookie-params.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.session-start.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.session-set-save-handler"
></A
>session_set_save_handler</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN204072"
></A
><P
>    (PHP 4, PHP 5)</P
>session_set_save_handler&nbsp;--&nbsp;
     Define a sequência de funções de armazenamento 
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN204075"
></A
><H2
>Descrição</H2
>bool <B
CLASS="methodname"
>session_set_save_handler</B
> ( callback open, callback close, callback read, callback write, callback destroy, callback gc )<BR
></BR
><P
>&#13;     <B
CLASS="function"
>session_set_save_handler()</B
> define a sequência 
     de funções de armazenamento  que é usada para guardar e devolver
     dados associados à sessão. Esta é mais usual quando um
     quando um método de armazenamento, a não ser que aquele oferecido por 
     sessões do PHP seja preferível.  i.e. Guardar dados de sessão em um
     banco de dados local.
     Retorna <TT
CLASS="constant"
><B
>TRUE</B
></TT
> em caso de sucesso ou <TT
CLASS="constant"
><B
>FALSE</B
></TT
> em falhas.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      A função "write" handler não é executada até depois que o fluxo de saída
      esteja fechado. Assim, a saída de instruções debugging na função
      "write" handler poderá nunca ser vista pelo navegador. Se a saída 
      debugging é necessária, ao invés disso é sugerido que a saída debug 
      seja escrita para um arquivo.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     O seguinte exemplo oferece um aramzenamento de sessão baseado em
      arquivos similar a sessões de PHP padrões save handler
     <CODE
CLASS="parameter"
>files</CODE
>.  Este exemplo poderia facilmente ser
     extendido para outras bases de dados usando seu gerente de banco de dados favorito suportado pelo PHP.
    </P
><P
>&#13;     A função "Read" deve retornar um valor string sempre que fizer o save handler
      trabalhar como o esperado. Retorna uma string vazia se não existe dados para
     ler. Retorna valores de outros handlers que estejam convertidos para expressões booleanas. TRUE em sucesso, FALSE em falha.
    </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Atenção</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;      Os manipuladores Write e Close são chamados após os objetos serem destruídos desde o PHP
      5.0.5. Então destruidores podem usar sessões mas o manipulador de sessão não pode usar
      objetos. Em versões anteriores, eles eram chamados na ordem oposta. è
      possível usar <A
HREF="function.session-write-close.html"
><B
CLASS="function"
>session_write_close()</B
></A
> a partir do
      destruidor para resolver este problema da galinha e do ovo.
     </P
></TD
></TR
></TABLE
></DIV
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN204111"
></A
><P
><B
>Exemplo 1. 
       <B
CLASS="function"
>session_set_save_handler()</B
> exemplo
      </B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">function </font><font color="#0000BB">open</font><font color="#007700">(</font><font color="#0000BB">$save_path</font><font color="#007700">, </font><font color="#0000BB">$session_name</font><font color="#007700">) <br />{<br />&nbsp;&nbsp;global </font><font color="#0000BB">$sess_save_path</font><font color="#007700">, </font><font color="#0000BB">$sess_session_name</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;</font><font color="#0000BB">$sess_save_path </font><font color="#007700">= </font><font color="#0000BB">$save_path</font><font color="#007700">;<br />&nbsp;&nbsp;</font><font color="#0000BB">$sess_session_name </font><font color="#007700">= </font><font color="#0000BB">$session_name</font><font color="#007700">;<br />&nbsp;&nbsp;return(</font><font color="#0000BB">true</font><font color="#007700">);<br />}<br /><br />function </font><font color="#0000BB">close</font><font color="#007700">() <br />{<br />&nbsp;&nbsp;return(</font><font color="#0000BB">true</font><font color="#007700">);<br />}<br /><br />function </font><font color="#0000BB">read</font><font color="#007700">(</font><font color="#0000BB">$id</font><font color="#007700">) <br />{<br />&nbsp;&nbsp;global </font><font color="#0000BB">$sess_save_path</font><font color="#007700">, </font><font color="#0000BB">$sess_session_name</font><font color="#007700">;<br /><br />&nbsp;&nbsp;</font><font color="#0000BB">$sess_file </font><font color="#007700">= </font><font color="#DD0000">"$sess_save_path/sess_$id"</font><font color="#007700">;<br />&nbsp;&nbsp;if (</font><font color="#0000BB">$fp </font><font color="#007700">= @</font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#0000BB">$sess_file</font><font color="#007700">, </font><font color="#DD0000">"r"</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$sess_data </font><font color="#007700">= </font><font color="#0000BB">fread</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#0000BB">filesize</font><font color="#007700">(</font><font color="#0000BB">$sess_file</font><font color="#007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;return(</font><font color="#0000BB">$sess_data</font><font color="#007700">);<br />&nbsp;&nbsp;} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;return(</font><font color="#DD0000">""</font><font color="#007700">); </font><font color="#FF8000">// Must return "" here.<br />&nbsp;&nbsp;</font><font color="#007700">}<br /><br />}<br /><br />function </font><font color="#0000BB">write</font><font color="#007700">(</font><font color="#0000BB">$id</font><font color="#007700">, </font><font color="#0000BB">$sess_data</font><font color="#007700">) <br />{<br />&nbsp;&nbsp;global </font><font color="#0000BB">$sess_save_path</font><font color="#007700">, </font><font color="#0000BB">$sess_session_name</font><font color="#007700">;<br /><br />&nbsp;&nbsp;</font><font color="#0000BB">$sess_file </font><font color="#007700">= </font><font color="#DD0000">"$sess_save_path/sess_$id"</font><font color="#007700">;<br />&nbsp;&nbsp;if (</font><font color="#0000BB">$fp </font><font color="#007700">= @</font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#0000BB">$sess_file</font><font color="#007700">, </font><font color="#DD0000">"w"</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;return(</font><font color="#0000BB">fwrite</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#0000BB">$sess_data</font><font color="#007700">));<br />&nbsp;&nbsp;} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;return(</font><font color="#0000BB">false</font><font color="#007700">);<br />&nbsp;&nbsp;}<br /><br />}<br /><br />function </font><font color="#0000BB">destroy</font><font color="#007700">(</font><font color="#0000BB">$id</font><font color="#007700">) <br />{<br />&nbsp;&nbsp;global </font><font color="#0000BB">$sess_save_path</font><font color="#007700">, </font><font color="#0000BB">$sess_session_name</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;</font><font color="#0000BB">$sess_file </font><font color="#007700">= </font><font color="#DD0000">"$sess_save_path/sess_$id"</font><font color="#007700">;<br />&nbsp;&nbsp;return(@</font><font color="#0000BB">unlink</font><font color="#007700">(</font><font color="#0000BB">$sess_file</font><font color="#007700">));<br />}<br /><br /></font><font color="#FF8000">/*********************************************<br /> * WARNING - You will need to implement some *<br /> * sort of garbage collection routine here.&nbsp;&nbsp;*<br /> *********************************************/<br /></font><font color="#007700">function </font><font color="#0000BB">gc</font><font color="#007700">(</font><font color="#0000BB">$maxlifetime</font><font color="#007700">) <br />{<br />&nbsp;&nbsp;return </font><font color="#0000BB">true</font><font color="#007700">;<br />}<br /><br /></font><font color="#0000BB">session_set_save_handler</font><font color="#007700">(</font><font color="#DD0000">"open"</font><font color="#007700">, </font><font color="#DD0000">"close"</font><font color="#007700">, </font><font color="#DD0000">"read"</font><font color="#007700">, </font><font color="#DD0000">"write"</font><font color="#007700">, </font><font color="#DD0000">"destroy"</font><font color="#007700">, </font><font color="#DD0000">"gc"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">session_start</font><font color="#007700">();<br /><br /></font><font color="#FF8000">// proceed to use sessions normally<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     Veja também a diretiva de configuração <A
HREF="ref.session.html#ini.session.save-handler"
>session.save_handler</A
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.session-set-cookie-params.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.session-start.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>session_set_cookie_params</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.session.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>session_start</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>