Jump to content

$_SERVER Variable issue?


wmguk

Recommended Posts

Hey,

 

I currently include a file called audit.php on all my php pages.

 

<?php
$user = $_SESSION['username'] ;

  include ("connection.php");
  
  if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db($db, $con);
  
  $user = $_SESSION['username'] ;
  $pageurl = $_SERVER['REQUEST_URI'];

mysql_query("INSERT INTO audit (user, pageurl) VALUES ('$user', '$pageurl');"); 
?>

 

however the $pageurl just shows http://www.domain.co.uk/audit.php and not the page that is including audit.php

 

how can i specify the main page, not the included page?

Link to comment
https://forums.phpfreaks.com/topic/136374-_server-variable-issue/
Share on other sites

Post some code that includes audit.php

 

??? If you want to help solve this issue I would post the top part of the file that include audit.php

 

sorry, i did try but phpfreaks wouldnt let me repost quickly then IE crashed.... anyway:

 

<?php
session_start(); 
if (!isset($_SESSION['username'])) {
header('Location: http://www.domain.co.uk/admin');
    exit; } 
$name = $_SESSION['name'] ;
$admin = $_SESSION['admin'];
$adminlevel = $_SESSION['adminlevel'];
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include ("http://www.domain.co.uk/admin/scripts/audit.php");
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>domain</title>
<META NAME="keywords" CONTENT="domain">
<META NAME="description" CONTENT="domain.">
<link href="../domain.css" rel="stylesheet" type="text/css" />
<script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="../SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>
<body>

Why are you including the URL?

 

<?php
include ("/admin/scripts/audit.php");
?>

 

Should work given that is the right spot in the file structure.

 

If that does not work try this:

<?php
include ($_SERVER['DOCUMENT_ROOT'] . "/admin/scripts/audit.php");
?>

 

Including it as a webpage, the webpage does not know it is being included, so it is set to audit.php. The above will set it to the page it is included on.

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.