View previous topic :: View next topic |
Author |
Message |
haydies Just Arrived
Joined: 19 Apr 2002 Posts: 0 Location: Hades
|
Posted: Sat May 18, 2002 6:59 am Post subject: PHP - Cookie |
|
|
Any one happen to know how to use cookies in PHP?
My page writes to the cookie ok, but it can't seem to read it, the varibles are always unset....
This has been driving me nuts all night....
|
|
Back to top |
|
|
ShaolinTiger Forum Fanatic
Joined: 18 Apr 2002 Posts: 16777215 Location: Kuala Lumpur, Malaysia
|
Posted: Sat May 18, 2002 3:40 pm Post subject: |
|
|
This is what it has in the phpBB index.php, doesn't make any sense to me but you might find it useful?
Code: |
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
$viewcat = ( !empty($HTTP_GET_VARS[POST_CAT_URL]) ) ? $HTTP_GET_VARS[POST_CAT_URL] : -1;
if( isset($HTTP_GET_VARS['mark']) || isset($HTTP_POST_VARS['mark']) )
{
$mark_read = ( isset($HTTP_POST_VARS['mark']) ) ? $HTTP_POST_VARS['mark'] : $HTTP_GET_VARS['mark'];
}
else
{
$mark_read = '';
}
//
// Handle marking posts
//
if( $mark_read == 'forums' )
{
if( $userdata['session_logged_in'] )
{
setcookie($board_config['cookie_name'] . '_f_all', time(), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
}
$template->assign_vars(array(
"META" => '<meta http-equiv="refresh" content="3;url=' .append_sid("index.$phpEx") . '">')
);
$message = $lang['Forums_marked_read'] . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a> ');
message_die(GENERAL_MESSAGE, $message);
}
//
// End handle marking posts
//
$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_t"]) : array();
$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_f"]) : array();
|
|
|
Back to top |
|
|
torrent Just Arrived
Joined: 05 May 2002 Posts: 0 Location: UK
|
Posted: Sat May 18, 2002 8:43 pm Post subject: |
|
|
If you are using version 4.1.x or above then grab the cookie vars from $_COOKIE['yourCookie'].
|
|
Back to top |
|
|
pauldude Just Arrived
Joined: 20 May 2002 Posts: 0 Location: Perthshire, Scotland
|
Posted: Wed May 22, 2002 11:48 am Post subject: |
|
|
There are 2 kinds of cookies, session cookies (which only apply to one instance of a browser) and expiring cookies (which will remain after the browser dies). I suspect that you are setting session cookies by using setCookie... This is a couple of lines from my Affiliate scheme redirecting:
header("Set-Cookie: affil=$aff; expires=Friday, 16-Jan-2037 00:00:00 GMT; path=/;");
header("Refresh: 0; url=$newurl");
then in future php scripts I simply use if (isset($affil)) { ...
Just make sure that you call header between <head> and </head>!!!
Paul
|
|
Back to top |
|
|
big tom Forum Fanatic
Joined: 28 May 2002 Posts: 16777215 Location: UK
|
Posted: Mon Jun 10, 2002 10:44 pm Post subject: headers |
|
|
If you just send the variable you want setting as a cookie with a form to a page that sets the cookie:
Code: |
<?php
setcookie("output_from_cookie", "$input_value");
header("location: next_page.php");
?>
|
Then when you are redirected to the next page the cookie should be able to be read as a normal variable:
Code: |
<?php
echo "$output_from_cookie";
?>
|
Good luck.
|
|
Back to top |
|
|
|