|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
SetCookie Error
Good afternoon,
I have a wierd problem I thought I might post here and see if anyone has run into before (and the solution if they found it). I am using a modified versoin of PHP Helpdesk from SourceForge.net. It uses cookies to do some authentication measures and present the user who is logged in with the tickets they need. And until recently, it was working well. I suspect that my host has recently upgraded their version of PHP, but I can't be sure. Anyway, until recently, as I stated, it was working well. Now I am getting the following error when trying to log in: Warning: setcookie() expects parameter 3 to be long, string given in /path/to/files/helpdesk/includes/cookie.inc.php on line 8 The cookie.inc.php is actually quite a small file and I would not think that it would cause me much grief, but it is. Below is the actual code for the cookie generation script: <?php // Modified by Andrew Walker (ajwalker@home.com) $time = mktime()+$g_cookietimeout; $date = date("l, d-M-y H:i:s", ($time)); if (isset($authentication)) { setcookie("status", $status, $date); setcookie("user", $user, $date); setcookie("group", $group, $date); setcookie("authentication", $authentication, $date); setcookie("laston", $laston, $date); } else { setcookie("status", "Logged In", $date); setcookie("user", $txtUsername, $date); setcookie("group", $row[4], $date); setcookie("authentication", "YES", $date); setcookie("laston", $row[6], $date); } ?> Now as you can see, the third parameter that is referred to is the $date variable. That refers back to a function in which it defines the date format, which should be day, date, time...something like Monday, 17-Jun-02 11:30:00 and then it refers to the mktime command and that calls a reference to the cookie timed out which is set in the configuration script. In the configuration script, it simply adds a numeric amount of second after which time the cookie will expire, in this case 1800 seconds or a half an hour. Now it was working...all of a sudden it's not. It makes reference that it is looking for I am guessing a long date? But what am I missing here? I have tried to set the year to a four digit year, full length on everything and I am having no luck at all. Any help would be greatly appreciated. |
|
#2
|
|||
|
|||
|
RE: SetCookie Error
Well, after doing a little research, it looks like lots of people are complaining about this error with this script.
Basically, the problem is that setcookie takes an integer for the third argument, not a string. The value of $time should be a valid value to pass to setcookie(). I would change all the $date references to $time in all the setcookie functions. What most likely happened was that your host used to suppress those warnings and now isn't...Let me know how it goes! |
|
#3
|
|||
|
|||
|
RE: SetCookie Error
Thanks for the input. On the other places that I have quoted, they also said the same thing. Three in a row...guess someone must know what their doing even if I don't.
I changed it and that changed the error message I am getting now, but it hasn't cured it as yet. The error I am now getting is as follows: Warning: Cannot add header information - headers already sent by (output started at /home/affiliat/public_html/helpdesk/includes/functions.inc.php:75) in /home/affiliat/public_html/helpdesk/includes/cookie.inc.php on line 8 For some reason it makes a call back to the functions.inc.php. I have seen this error before when I dabbled with the different settings in the cookie.inc.php and couldn't find anything that might generate such an error inside of that script. It also is relatively small in comparison to some parts of the script and its content is as below: <?php // Global Functions if( isset( $FUNCTIONS ) ) { return; } $FUNCTIONS=1; include("includes/connect.inc.php"); /* * showSummary - Display current open tickets and open tickets for * the current user. */ function showSummary() { global $user, $mysql_link; $openTickets = 0; $userTickets = 0; $query = "SELECT events.e_id, events.t_id, events.e_status, " . "events.e_assignedto, ticket.t_id FROM events,ticket " . " WHERE events.t_id = ticket.t_id ORDER BY " . " events.t_id, events.e_id;"; $result = query( $query ); $row = mysql_fetch_row( $result ); $prev_e_id = $row[0]; $prev_t_id = $row[1]; $prev_e_status = $row[2]; $prev_e_assignedto = $row[3]; $done = 0; while( !$done ) { $row = mysql_fetch_row( $result ); if( !$row ) { $done = 1; } $e_id = $row[0]; $t_id = $row[1]; $e_status = $row[2]; $e_assignedto = $row[3]; if( $t_id != $prev_t_id ) { if( $prev_e_status == "OPEN" ) { $openTickets++; if( $prev_e_assignedto == $user && isset($user) ) $userTickets++; } } $prev_e_id = $e_id; $prev_t_id = $t_id; $prev_e_status = $e_status; $prev_e_assignedto = $e_assignedto; } print "Open Tickets: $openTickets<br>n"; print "Assigned to you: $userTickets<br>n"; } /* * query( $queryString ) Execute query on MySQL and report any errors * * If $debug flag is set in config/general.conf.php, some debugging * information is printed such as the SQL statement sent to the back end. */ function query( $q ) { global $mysql_link; global $debug; if( $debug >= 1 ) echo "<br>Executed SQL: <b>$q</b>"; $result = mysql_query( $q, $mysql_link ); unset( $error ); $error = mysql_error( $mysql_link ); if( $error ) echo "<br><b>SQL ERROR: </b>$error<br>"; if( $debug >= 1 ) echo " (" . (0+mysql_affected_rows($mysql_link)) . " rows affected.)<br>"; return $result; } /* * heading( $headingText ) * * This function prints a heading on the page. This is intended to * make a consistant heading style for all pages within the helpdesk. */ function heading( $text, $center ) { if( $center ) print "<center>"; print "<hr><h1>$text</h1><hr>"; if( $center ) print "</center>"; } /* * timestampToUnix( $timestamp ) * * Converts a MySQL timestamp to a unix integer date. */ function timestampToUnix( $t ) { $YYYY = $MM = $DD = $hh = $mm = 0; $YYYY = "$t[0]$t[1]$t[2]$t[3]"; $MM = "$t[4]$t[5]"; $DD = "$t[6]$t[7]"; $hh = "$t[8]$t[9]"; $mm = "$t[10]$t[11]"; return strtotime("$YYYY-$MM-$DD $hh:$mm:00"); } ?> Now if I can figure this out and lock the problem down, I can put this thing back together again. Never realize how much you are dependent on something until its broke. In answer to your question, yes, they did change something recently. I know that they said a couple of weeks ago they upgraded the PHP version to 4.2 because of security holes in the previous version. I had thought that the most recent version was 4.6, but maybe I am offbase. In any case, if someone out there can see something I don't, I would greatly appreciate it. |
|
#4
|
|||
|
|||
|
RE: SetCookie Error
Well, line 75 in functions.php is this:
echo "<br>Executed SQL: <b>$q</b>"; and 74 is this: if( $debug >= 1 ) That tells me that you may have the $debug variable set to 1 or greater in the config/general.conf.php file. Check that file and make sure the $debug variable is set to 0.... |
|
#5
|
|||
|
|||
|
RE: SetCookie Error
Heck, if that fixes it than I will have been bashing my head against the wall for nothing!! I turned that on yesterday when I started to get the first message. That sort of "single-steps" the script down through each of the calls. Not that it has done me a lot of good as it simply shows me all of the steps that ran correctly, displays the error and then keeps on astepin'.
I will turn it off. You never can tell. It might be the source of all of my problems. I will shut it off and see what happens. |
|
#6
|
|||
|
|||
|
RE: SetCookie Error
Well, I'll be hornswaggled!! It worked!!! Something to do with the debug script sent it into a panic. And as soon as I shut it off, I got an error message stating that line 10, 11, and 12 were short again...like the first message. This was wierd because I had expected that if I got any error, the error line would have started at 8 and go through 12 including all five lines. Went back into the code and I could see where I missed a $date. I swapped that for $time and VOILA!
Hey, you guys are great! Makes Microsucks - I mean Microsoft look sorry in comparison. Too made Diablo II and Starcraft don't run on Linux, otherwise, I would be a Linux baby at home right now! Thanks again for all your help, Matt. I have to "reestablish" some code that I took out thinking that might have been the problem. And I also have some serious thanking to do around the internet for the different input at the different places. Wow! What a nightmare. But that cured it and it was curred right. That reminds me...I better get up to SourceForge and put the modified file up there for those people. I also have some added stuff that others might be interested in like extended company (customer) information and an additional script to modify that information for them. Again, like I said, it was hard to say WHAT broke it. I have severely modified mine to make it do what I need it do. Wow!! Can't thank you enough, Matt. Between you and the others, this is good. I will be here more often, I am sure! |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > SetCookie Error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
![]() |
|