Forum Moderators: coopster

Message Too Old, No Replies

Help with Sessions

         

jeep98

11:35 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



I'm new to sessions and am having some trouble getting them to work. Here is my current code that I've scrapped together by reading a few tutorials:

<?php

$mkid = $_GET['MKID'];
if(isset($mkid)){
session_start();
$_SESSION['MKID'] = $mkid;
}

session_start();
if(!isset($_SESSION['MKID']))
$_SESSION['MKID'] = 0;

?>

My goal here is to get the variable "MKID" from an incoming url and stick that variable into a session for future use (on any page of my site). If an incoming link doesn't have an MKID value, I just want to set it to zero. The current code throws a bunch of PHP errors at me ("Cannot send session cookie - headers already sent").

Thanks.

Kroberts

12:32 am on Aug 12, 2005 (gmt 0)



Usually cookies need to be sent before anything else.

jeep98

2:06 am on Aug 12, 2005 (gmt 0)

10+ Year Member



Figured it out. I think the main problem was empty spaces before my php tag. Thanks.

coopster

2:07 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yep, that will do it. Thanks, Kroberts, and welcome to WebmasterWorld.