Jump to content

How I Fix This Error...


thara

Recommended Posts

can anybody tell me what this message mean?

Notice: Undefined index: HTTP_REFERER in C:\wamp\www\pageviews.php on line 14

 

this is my code...

 

<?php
session_start();

require_once ('test.php');

echo '<pre>';
  print_r( $_SERVER);
echo '</pre>';

$ip = $_SERVER['REMOTE_ADDR'];
$ip = ip2long($ip);

$browser = $_SERVER['HTTP_USER_AGENT'];
$referer = $_SERVER['HTTP_REFERER'];
$url = $_SERVER['REQUEST_URI'];
$session = session_id();

$query = "INSERT INTO page_views SET ip = '$ip', browser = '$browser', url = '$url', session_id = '$session', start_time = NOW()";
$result = mysqli_query($dbc, $query);

 if ( $result ) {
  echo 'good'; 
 } else { echo 'bad'; 
  echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $query . '</p>'; // Debugging message.
 }

?>

Link to comment
https://forums.phpfreaks.com/topic/269186-how-i-fix-this-error/
Share on other sites

$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;

 

Because I don't like repeating myself I tend to not use the array's directly, for example:

 

class SilentArrayObject extends ArrayObject {
 public function offsetGet($offset) {
   if (!$this->offsetExists($offset)) {
     return null;
   }
   return parent::offsetGet($offset);
 }
}

 

$_SERVER = new SilentArrayObject($_SERVER);

 

Then I can simply write:

 

$referer = $_SERVER['HTTP_REFERER'];

 

Which results in null when it does not exist (which is the default behavior anyway).

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.