Jump to content

Die and go to... (Error and Header control)


NevadaSam

Recommended Posts


[b]Problem[/b]: When my hit counter scripts crash, visitors won't be forwarded to the site.

[b]Discussion[/b]: I use a MySql data base to record the number of hits from different forwarded domains. Yesterday I changed the user password on the account for other reasons without realizing what it would do to my hits counter table access. The results were when the script tried to record the hit and forward a visitor they would see error messages on the screen, the script would die and couldn't be forward with the header() because output from the Warnings and Notices had already been sent. I realize there was something wrong when I check for hits today and saw zero where there should have been over 200.

I do not need to get errors, warning, or notices if the scripts fail. It is nice to have the count, but more important for the visitor to be forwarded to the final destination. 

[b]Solutions[/b]: I have came up with this code. I have tested in with every situation I can think of (bad login info, db not found, and now table) and it either records the hit and forwards or just forwards. It seems to work find and will prevent what happen from happening again.

I would like for others to see it and let me know if you see any possible problems I might have over looked. What variable information which is not shown is in the include file.

[code]<?php
error_reporting(0);
include ("hits.inc");

$CTfrom = 'cosbynet';
$DBConnect = mysqli_connect("$host","$user","$password");
if (!$DBConnect)
header($Location);

$db = mysqli_select_db($DBConnect, $DBName);
if (!db)
header($Location);

$QuerySend = "INSERT INTO $TableName
VALUES(NULL, '$CTdate', '$CTtime', '$CTfrom')";
$QueryResult = mysqli_query($DBConnect, $QuerySend);
if (!$QuerySend || !$QueryResult)
header($Location);

mysqli_close($DBConnect);
header($Location);
?>[/code]

Sorry about the long post. I appreciate any advice you might have.

Sam
;
Link to comment
https://forums.phpfreaks.com/topic/33939-die-and-go-to-error-and-header-control/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.