Jump to content

[SOLVED] Assigning a new string to $_SERVER['phpself']


nafetski

Recommended Posts

Hello everyone =)  I'm semi-new to PHP, but yesterday my boss asked me to make a website traffic monitoring system.  Right now it posts the username / password / PHP SELF / and datetime to a database that we can later view.

 

I'm outputting all the data into a table, when it was brought to my attention that the part of our company that is non tech will find the URL from PHP SELF to not be that helpful.  How can I change something like /dirtbikes/dbsales.php to "Dirtbike Sales Page"?

 

I could set a variable in each page that is posted, but I really would like to find a way to do it that doesn't involve me editing 100 files :D  Thanks!

Link to comment
Share on other sites

I could set a variable in each page that is posted, but I really would like to find a way to do it that doesn't involve me editing 100 files  Thanks!

 

Well, php has no idea that the page /dirtbikes/dbsales.php is "Dirtbike Sales Page".

 

If your setting the <title> of each page using a variable you may be able to use that. Otherwise, you'll need to (at least) create an array of addresses -> descriptions.eg;

 

<?php

  $descriptions = array(
    '/dirtbikes/dbsales.php' => 'Dirtbike Sales Page'
  );

?>

 

Then when you go to create your log entry you could use...

 

<?php

  $descriptions[$_SERVER['PHP_SELF']];

?>

Link to comment
Share on other sites

Yes!  That's almost exactly what I need.

 

The only thing I have to contend with is that the root of my local machine isn't the same as our production server.  is there any way that I could make it where only

 

"..dbsales.php" = "Dirtbike Sales Page" ?

 

Thank you so much for responding!

Link to comment
Share on other sites

I would create a new table that stores the page name and a description.  Then you can compare and populate the right value.

 

This will also make it easy for you to add new pages/descriptions without having to change the code.

Link to comment
Share on other sites

Got it to work =)

 

$fileexplode = explode("/",$_SERVER[php_SELF]);
$filename = array_pop($fileexplode);

$descriptions = array{
     'data.php' => 'This is my first page of data',

}

$descriptions[$filename]
(

 

Works like a charm, thanks for pointing me in the right direction!

 

(Just saw your reply thorpe, that's even easier hah)

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.