• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

PHP - Cookie

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More

View previous topic :: View next topic  
Author Message
haydies
Just Arrived
Just Arrived


Joined: 19 Apr 2002
Posts: 0
Location: Hades

Offline

PostPosted: Sat May 18, 2002 6:59 am    Post subject: PHP - Cookie Reply with quote

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
View user's profile Send private message Visit poster's website
ShaolinTiger
Forum Fanatic
Forum Fanatic


Joined: 18 Apr 2002
Posts: 16777215
Location: Kuala Lumpur, Malaysia

Offline

PostPosted: Sat May 18, 2002 3:40 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
torrent
Just Arrived
Just Arrived


Joined: 05 May 2002
Posts: 0
Location: UK

Offline

PostPosted: Sat May 18, 2002 8:43 pm    Post subject: Reply with quote

If you are using version 4.1.x or above then grab the cookie vars from $_COOKIE['yourCookie'].
Back to top
View user's profile Send private message Visit poster's website
pauldude
Just Arrived
Just Arrived


Joined: 20 May 2002
Posts: 0
Location: Perthshire, Scotland

Offline

PostPosted: Wed May 22, 2002 11:48 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
big tom
Forum Fanatic
Forum Fanatic


Joined: 28 May 2002
Posts: 16777215
Location: UK

Offline

PostPosted: Mon Jun 10, 2002 10:44 pm    Post subject: headers Reply with quote

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
View user's profile Send private message
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Looking for more Windows Networking info?

Sign up to the WindowsNetworking.com Monthly Newsletter, written by Enterprise Security MVP Deb Shinder, containing news, the hottest tips, Networking links of the month and much more. Subscribe today and don't miss a thing!
View a sample newsletter.

Become a WindowsNetworking.com member!

Discuss your Windows Networking issues with thousands of other Windows Newtorking experts. Click here to join!

Community Area

Log in | Register

Readers' Choice

Which is your preferred data recovery solution?

Follow TechGenix on Twitter