The note about an included file not being able to access the sessions is not true. You just have to do a session_start(); in the included file.
This is what drove me here today, because I was noticing the same thing. But I tried the above on a whim and it works fine. You wouldn't think you'd need to start a session twice, but I guess the scripts are looked on as separate in that regard.
Mike
Manipulação de Sessão
- Introdução
- Instalação/Configuração
- Constantes pré-definidas
- Exemplos
- Sessões e segurança
- Funções para Sessão
- session_cache_expire — Retorna o prazo do cache atual
- session_cache_limiter — Obtém e/ou define o limitador do cache atual
- session_commit — Sinônimo de session_write_close
- session_decode — Decifra dado de sessão de uma string
- session_destroy — Destrói todos os dados registrados em uma sessão
- session_encode — Codifica os dados da sessão atual como uma string
- session_get_cookie_params — Obtém os parâmetros do cookie da sessão
- session_id — Obtém e/ou define o id de sessão atual
- session_is_registered — Descobre se uma variável global está registrada numa sessão
- session_module_name — Obtém e/ou define o módulo da sessão atual
- session_name — Obtém e/ou define o nome da sessão atual
- session_regenerate_id — Atualiza o id da sessão atual com um novo gerado
- session_register — Registrar uma ou mais variáveis globais na sessão atual
- session_save_path — Obtém e/ou define o save path da sessão atual
- session_set_cookie_params — Define os parâmetros do cookie de sessão
- session_set_save_handler — Define a sequência de funções de armazenamento
- session_start — Inicia dados de sessão
- session_unregister — Desregistra uma variável global da sessão atual
- session_unset — Libera todas as variáveis de sessão
- session_write_close — Escreve dados de sessão e termina a sessão
Sessões
mike at basementideas dot com
08-Jul-2008 02:05
08-Jul-2008 02:05
pushedx
02-Jul-2008 12:01
02-Jul-2008 12:01
Here is something to watch out for when working with sessions.
Let's say you have two pages, Page A and Template Z. If Page A sets session data and includes Template Z, the session data is not properly registered for the execution of Template Z due to how session data is written *after* a script has executed [1].
As a result, your second page will not have the right session data, so you are a bit in a pickle. I'm sure there are other work arounds, perhaps with cookies or flat files, but you cannot use session data in that fashion.
The reason I have this setup is because I will have a number of Page A-Z's that will contain page specific content and one Template Z page that renders each page's specific content in the site layout. This way, the site content changing is independent of the style the site uses and the site style can change without modifying the actual content. It's a dynamically configurable site template design.
[1] See the "session_write_close" documentation page.
