2
   

PHP: Cookie Problem

 
 
Reply Sun 24 Aug, 2003 12:55 am
Whenever a visitor visits the 404.php page, the script will send data to the functions.inc.php file saying this is error 404. Then it will check if the user has a cookie for that page, if not, then a cookie will be set, and then an e-maill will be sent to the specified address.
If the person already has a cookie for that specific page, then no e-mail will be sent. However, I keep getting an e-mail everytime someone visits the page. So there is something wrong with the cookie part.
Any ideas?

Code:<?php

// Generator v2.0 Coded by: WWW.MRBOBDOUGLAS.COM, Script by JdS
// Begin PHP Code

// FILENAME: 404.PHP

// include the filenamed : functions.inc.php...
// assuming that both files are in the same directory
include_once( $_SERVER['DOCUMENT_ROOT'].'/errorpgs/functions.inc.php' );

// Everytime someone reaches this page, i.e. 404.php, an email gets sent out
send_error_email( '404' );


// Generator v2.0 Coded by: WWW.MRBOBDOUGLAS.COM, Script by JdS
// End PHP Code //

?>



***************And the functions.inc.php file:************


Code:<?php

// Generator v2.0 Coded by: WWW.MRBOBDOUGLAS.COM, Script by JdS
// Begin PHP Code

// FILENAME: FUNCTIONS.INC.PHP
function is_reported()
{

// SET THE DOMAIN NAME BELOW (without the 'http://' or 'www' bits)
$domain = 'mrbobdouglas.com';

// ---------------------------------------------------------------

if( isset($_COOKIE['http_errors']) )
{
$_COOKIE['http_errors'] = unserialize( $_COOKIE['http_errors'] );

if( in_array($_SERVER['REQUEST_URI'], $_COOKIE['http_errors']) )
{
// this error page / url has been reported by this person before
return TRUE;
}
}
// this person has either NEVER reported an error before
// or this is a NEW url error to report
$_COOKIE['http_errors'][] = $_SERVER['REQUEST_URI'];
$value = serialize( $_COOKIE['http_errors'] );
setcookie( 'http_errors', $value, time() + 24*60*60, '/', './'.$domain, 0 );
unset( $domain, $value );
return FALSE;
}

function send_error_email( $error_code='Undefined' )

{
if( !is_reported() )
{
// set the TO: email address
$to = '[email protected]';

// set the SUBJECT: e-mail
$subject = "An error has occured - type: $error_code";

// set the MESSAGE: e-mail
$message = "The following error has occured:\r\n"

."--------------------------------\r\n\r\n"
." Type: $error_code\r\n"
." Page: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}\r\n"
." Time: ".date('d/m/Y H:i:s')."\r\n"
." From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Regards,\r\n"
."Your hard-working web server.";

$headers = "From: webserver@{$_SERVER['SERVER_NAME']}\n"
."Reply-To: webserver@{$_SERVER['SERVER_NAME']}\n"
."X-Mailer: PHP/".phpversion();

// send the email
mail( $to, $subject, $message, $headers );
}
}
// Generator v2.0 Coded by: WWW.MRBOBDOUGLAS.COM, Script by JdS
// End PHP Code
?>


Thanks
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 2 • Views: 3,651 • Replies: 9
No top replies

 
Craven de Kere
 
  1  
Reply Sun 24 Aug, 2003 05:23 am
Your script is not setting cookies. I'll have to pore through it later on to tell you why.
0 Replies
 
Craven de Kere
 
  1  
Reply Sun 24 Aug, 2003 05:49 am
BTW, I noticed you used some fixes from some other questions you posed. It'd be cool if you post that they are resolved so that those answering know the issue is closed and so that those who happen upon the thread in the future know that the solution is viable.
0 Replies
 
BobbyDouglas
 
  1  
Reply Sun 24 Aug, 2003 02:07 pm
Ok, will keep up on it. I thought we the ending posts mentioned they worked, Ill go make a close on the ones that are not obvious.
0 Replies
 
Craven de Kere
 
  1  
Reply Sun 24 Aug, 2003 05:31 pm
functions.inc.php will set a cookie is you fix it up like so:

Code:
<?php

// Generator v2.0 Coded by: WWW.spammingsite.com, Script by JdS
// Begin PHP Code

// FILENAME: FUNCTIONS.INC.PHP
function is_reported()
{

// SET THE DOMAIN NAME BELOW (without the 'http://' or 'www' bits)
$domain = 'able2know.com';

// ---------------------------------------------------------------

if( isset($_COOKIE['http_errors']) )
{
$_COOKIE['http_errors'] = unserialize( base64_decode($_COOKIE['http_errors']) );

if( in_array($_SERVER['REQUEST_URI'], $_COOKIE['http_errors']) )
{
// this error page / url has been reported by this person before
return TRUE;
}
}
// this person has either NEVER reported an error before
// or this is a NEW url error to report
$_COOKIE['http_errors'][] = $_SERVER['REQUEST_URI'];
$value = serialize( $_COOKIE['http_errors'] );
setcookie( 'http_errors', base64_encode($value), time() + 24*60*60, '/', '.'.$domain, 0 );
unset( $domain, $value );
return FALSE;
}

function send_error_email( $error_code='Undefined' )

{
if( !is_reported() )
{
// set the TO: email address
$to = '[email protected]';

// set the SUBJECT: e-mail
$subject = "An error has occured - type: $error_code";

// set the MESSAGE: e-mail
$message = "The following error has occured:\r\n"

."--------------------------------\r\n\r\n"
." Type: $error_code\r\n"
." Page: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}\r\n"
." Time: ".date('d/m/Y H:i:s')."\r\n"
." From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Regards,\r\n"
."Your hard-working web server.";

$headers = "From: webserver@{$_SERVER['SERVER_NAME']}\n"
."Reply-To: webserver@{$_SERVER['SERVER_NAME']}\n"
."X-Mailer: PHP/".phpversion();

// send the email
mail( $to, $subject, $message, $headers );
}
}
// Generator v2.0 Coded by: WWW.spammingsite.com, Script by JdS
// End PHP Code
?>
0 Replies
 
BobbyDouglas
 
  1  
Reply Sun 24 Aug, 2003 07:00 pm
Thanks. Another friend just fixed it too. Its the same as what you posted tho. Thank you. Smile
0 Replies
 
Craven de Kere
 
  1  
Reply Sun 24 Aug, 2003 08:07 pm
Cool. I plan to use this code for my sites. Thing is, I'd like the generator as well. In another time I'd just 'borrow' it from you but heck I may as well ask. ;-)

Are you sharing the generator code?
0 Replies
 
BobbyDouglas
 
  1  
Reply Sun 24 Aug, 2003 08:51 pm
Of course you can. If you send me an e-mail I will send you updates as I update the script.

I plan to add a feature to it if you check a box, it will add another line of code, which will submit all error page results to a .txt file. And if the page is already listed, it wont be displayed again.

Also, if you dont mind, write a short review for it:

hot scripts DOT com/Detailed/25338.html
0 Replies
 
Craven de Kere
 
  1  
Reply Sun 24 Aug, 2003 09:09 pm
BTW, I plan to add code to the actual error page scripts. I'll keep you posted on those additions.
0 Replies
 
BobbyDouglas
 
  1  
Reply Sun 24 Aug, 2003 09:21 pm
Ok great, ty Razz
0 Replies
 
 

Related Topics

\n - Question by negikaithal
PHP question about parse_url - Question by markalanbaker1
What does \n mean in PHP Code? - Discussion by roverroad
PHP Debate - Discussion by Craven de Kere
Installing PHP with IIS - CGI Error - Discussion by skinnz
Displaying <?php in javascript. - Discussion by BobbyDouglas
php software - Question by aishna
 
  1. Forums
  2. » PHP: Cookie Problem
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 1.62 seconds on 11/24/2024 at 05:01:03