thara Posted October 7, 2012 Share Posted October 7, 2012 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. } ?> Quote Link to comment Share on other sites More sharing options...
ignace Posted October 7, 2012 Share Posted October 7, 2012 $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). Quote Link to comment Share on other sites More sharing options...
thara Posted October 7, 2012 Author Share Posted October 7, 2012 thanks for your help and your code... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.