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
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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.