nafetski Posted October 31, 2007 Share Posted October 31, 2007 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 Thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted October 31, 2007 Share Posted October 31, 2007 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']]; ?> Quote Link to comment Share on other sites More sharing options...
nafetski Posted October 31, 2007 Author Share Posted October 31, 2007 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! Quote Link to comment Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 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. Quote Link to comment Share on other sites More sharing options...
nafetski Posted October 31, 2007 Author Share Posted October 31, 2007 So a table that has two fields...one that has the file name, and one that has the description name? How would I compare/populate? Sorry, having a mental block type of day >_< Quote Link to comment Share on other sites More sharing options...
nafetski Posted October 31, 2007 Author Share Posted October 31, 2007 Would it be possible to explode(); the results of PHP_SELF, and take the last entry in the array? If I'm using "/" as a delimiter, that would make the file name be what I want! Quote Link to comment Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 That's where I would start first Quote Link to comment Share on other sites More sharing options...
trq Posted October 31, 2007 Share Posted October 31, 2007 You could simply use basename. <?php $descriptions = array( 'dbsales.php' => 'Dirtbike Sales Page' ); $descriptions[basename($_SERVER['PHP_SELF'])]; ?> Quote Link to comment Share on other sites More sharing options...
nafetski Posted October 31, 2007 Author Share Posted October 31, 2007 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) 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.