Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2002
    Location
    Central New York
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding Page Name, not Script Name

    It seems that this forum will be my new home for a few days... but that's okay, ya'll seem like a nice enough group of people.

    I want to write a short php script to act as a rudimentary stats gatherer. I'm thinking along the lines of writing one script, then including it in all the other pages. In other words, say I have index.shtml, about.shtml, and contact.php. I would like one script, stats.php, that I can use on the different pages (either by <!--#include file="php/stats.php"--> or include ("php/stats.php"); depending on how the page is parsed).

    It'll just dump all the data in the same file, something along the lines of:

    1. index.shtml 123.45.6.789 refr: yahoo.com Mozilla /4.0
    2. contact.php 123.45.6.789 refr: index.shtml Mozilla /4.0
    3. index.shtml 987.65.43.210 refr: google.com Opera 6.0
    4. index.shtml 123.45.6.789 refr: contact.php Mozilla /4.0
    5. about.shtml 987.65.43.210 refr: index.shtml Opera 6.0
    ...

    But to do that I'll need the page name into which the the script was included. I can't just use $PHP_SELF because it'll just return the name of the script, not the page (I even checked to see if there was a $HTTP_SELF... no luck).

    What variable am I looking for to find the name of the page in which stats.php has been inserted?!

    Thanks.
    Timothy Boronczyk

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,058
    Thanks
    10
    Thanked 96 Times in 94 Posts
    if you <?include 'stats.php';?> then $_SERVER['PHP_SELF'] should contain the name of the calling page not of stats.php


    so if foo.php was

    <?include 'bar.php';?>

    and

    bar.php contained

    <?echo $_SERVER['PHP_SELF'];?>

    then the output of foo.php should be '/foo.php'
    which is I think what you want ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Dec 2002
    Location
    Central New York
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, but it doesnt work for me.

    I have page.shtml which contains:
    <html>
    <h1>This page is: <!--#include file="script.php"--></h1>
    </html>

    and script.php contains:
    <?PHP
    echo $_SERVER['PHP_SELF'];
    ?>

    page.shtml displays:
    This page is: /script.php

    Any more suggestions? I know this has to be possible, it's just a matter of how.
    Timothy Boronczyk

  • #4
    New Coder
    Join Date
    Dec 2002
    Location
    Central New York
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Got it! It took a heck of a lot of researching and pestering programming gurus, but the variable I'm looking for is: $REQUEST_URI

    Just incase anyone else needs to know
    Timothy Boronczyk


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •