Jump to content

Archived

This topic is now archived and is closed to further replies.

mkosmosports

Using the REQUEST_URI statement...

Recommended Posts

I have the following variable defintition : $currentt = $_SERVER['REQUEST_URI'];
echoing this gives me the current URL that is being used. However, I would like to get it to only show the name of the html page that is being used.

For example, currently if the url is "http://localhost/index.htm?g=2&h=4", and I echo $currentt I want it only to return "index.htm" not the entire url...

Does anyone know of a way that this can be done?

Thanks.
mkosmosports

Share this post


Link to post
Share on other sites
Nevermind, the below script is working for me... :D

  $full_path = getenv("REQUEST_URI"); //retrieves the full url
  $pagename = basename($full_path); //retrieves the name of the html page youre using (with or without any url parameters)....

  $currentt = substr($pagename //makes sure only the html page name getx extracted...
  , strrpos($pagename, "/")
  , strpos($pagename, ".html"));

The above variable $currentt will extract the name of the current html page thats being used and nothing but....

Share this post


Link to post
Share on other sites
alternatively..

[code]<?php

echo $_SERVER['SCRIPT_NAME'];

?>[/code]

Share this post


Link to post
Share on other sites

×

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.