Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
When this page loads, I get the warnings, and I don't understand them. Anyone care to explain?
Page (view source for HTML):
http://perfectionconstruction.com/PHP code:
session_start();
if(!session_is_registered('counted')){
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$dtime = date('l F j, Y - g:i a');
$to = "robazar@earthlink.net";
if($ref == ""){
$ref = "None";
}
$entry = "$dtime \n IP: $ip \n Agent: $agent \n URL: $uri \n Referrer: $ref \n\n";
$fp = fopen("goodlog.txt", "a");
fputs($fp, $entry);
fclose($fp);
session_register('counted');
}

I just read this. Is this what causes the warnings?
"Before you can begin storing user information in your PHP session, you must first start the session. When you start a session, it must be at the very beginning of your code, before any HTML or text is sent."

(Forgive me while I talk to myself here!)
I added a couple lines to the PHP and the warnings went away. I don't understand it all but...Added:
$user = $_SERVER['PHP_AUTH_USER'];
and:
if($user == ""){
$user = "None";
}
$entry = "$dtime \n IP: $ip \n Agent: $agent \n URL: $uri \n Referrer: $ref \n $user \n\n";NOW the prob is that when I try to refresh the page w/ I.E.6, it gives another error, and the page doesn't load. If I try a "back to home" link on one of the other pages, same error. I.E.7 and Foxfire don't do that, but all of them post a new log each time the page is accessed or refreshed...(? is that a new session).
Hurting my brain here, but I'm not gonna quit!

I would suggest commenting all of your session specific code and uncomment the code line-by-line to see where the error exists.
But I "think" I see the error. The commond session_register() is deprecated and you don't seem to be using it correctly anyway. According to the manual the string inside the command should represent a global variable name. I don't see where you have defined $counted. ( http://us.php.net/manual/en/functio... )
Try this:
Change this:
if(!session_is_registered('counted')){
To This:
if($_SESSION['counted']!==true){
And change this:
session_register('counted');
To this:
$_SESSION['counted'] = true;
Michael J

I made the changes and it works much better. Thanks.
'cept, tho IE6 logs 1 visit no matter how many refreshes, Foxfire counts each refresh and logs it. Can't figure that one.
Also, launch the page and refresh with IE6 and you get the 500 error. That also happens when you click the "home" link on any of my other pages.

(talking to myself again...)
"Foxfire counts each refresh and logs it."
That's 'cause FF wasn't setting a cookie. When I allowed it (IE must've been allowed already), then:
"you get the 500 error"
To correct that, I moved a bit if the PHP code from one place to another, the "$-SESSION['counted'] =true" bit.
Two versions included below, the first barked the 500 error, the second flies. Don't ask!(not good:)
session_start();
if($_SESSION['counted']!== true){
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$user = $_SERVER['PHP_AUTH_USER'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$dtime = date('l F j, Y - g:i a');
$to = "robazar@earthlink.net";
if($ref == ""){
$ref = "None";
}
if($user == ""){
$user = "None";
}
$entry = "$dtime \n IP: $ip \n Agent: $agent \n URL: $uri \n Referrer: $ref \n $user \n\n";
$fp = fopen("goodlog.txt", "a");
fputs($fp, $entry);
fclose($fp);
$_SESSION['counted'] = true;$message = stripslashes("IP: $ip - DATE: $dtime" . "<br />" . $agent . "<br />" . "Ref\'d by: $ref");
$subject = ("A visit to your website");// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: PerfectionWebsite-";mail($to, $subject,
$message, $headers);}
(better:)
session_start();
if($_SESSION['counted']!== true){
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$user = $_SERVER['PHP_AUTH_USER'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$dtime = date('l F j, Y - g:i a');
$to = "robazar@earthlink.net";
if($ref == ""){
$ref = "None";
}
if($user == ""){
$user = "None";
}
$entry = "$dtime \n IP: $ip \n Agent: $agent \n URL: $uri \n Referrer: $ref \n $user \n\n";
$fp = fopen("goodlog.txt", "a");
fputs($fp, $entry);
fclose($fp);$message = stripslashes("IP: $ip - DATE: $dtime" . "<br />" . $agent . "<br />" . "Ref\'d by: $ref");
$subject = ("A visit to your website");// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: PerfectionWebsite-";mail($to, $subject,
$message, $headers);
$_SESSION['counted'] = true;
}

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |