Ted
Ted

Reputation: 3885

How can I tell which page serves me?

I am on a website. the URL reads something like https://somesite.com/serve

I need to tell the name of the page that is serving me.

Like index.html, index.htm, etc...

Upvotes: 1

Views: 98

Answers (6)

hellork
hellork

Reputation: 354

(Assuming server supports .htaccess, mod_rewrite, mod_headers)

Temporarily use .htaccess RewriteRule to reveal all or matching filenames in a header.

Example tags all php file headers with filename:

<IfModule mod_rewrite.c>
RewriteEngine on
    <IfModule mod_headers.c>
        RewriteRule .*\.php$ - [E=FILENAME:$0]
        <FilesMatch ".php$">
           Header set MY-COOL-FILENAME "filename=%{FILENAME}e"
        </FilesMatch>
    </IfModule>
</IfModule>

Links

Setting a filename inside the header with htaccess

View HTTP headers in Google Chrome?

Upvotes: 0

Jānis Gruzis
Jānis Gruzis

Reputation: 995

You want to know the file that is being served. Well probably you are facing url rewrite with htaccess or other techniques. To tell which file it is probably is impossible if only you manage to get framework (if it is framework) in which the page is made. Then you can read in documentation which is the file to which the requests are aimed. Most frameworks will have one or several of these files. For example codeignighter will have only index.php, while symfony 2 will have app.php and app_dev.php (and others if you want different environments). But normaly you cant know which file serves your request if url rewrite is made.


As mentioned @Dale you cant also beleave what urls say. Because you cant stick some extension at the end for it to look as file. Sometimes you can notice .php or more often .html / .htm at the end.

Upvotes: 1

Alfred
Alfred

Reputation: 61793

probably then you have a .htaccess with rewrite rules which looks something like:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Else you probably would have query string instead which probably looked something like:

index.php?c=products&m=view&id=345

Upvotes: 0

user1048676
user1048676

Reputation: 10076

If you just trying to find out the page name then you can do this:

<?php
$currentFile = $_SERVER["PHP_SELF"];
$parts = explode('/', $currentFile);
echo $parts[count($parts) - 1];
?>

Upvotes: 0

Mads
Mads

Reputation: 724

I'm not entirely sure what you mean. But I'm certain you can find it with $_SERVER (Documentation can be found here)

Good luck

Upvotes: 0

SLaks
SLaks

Reputation: 888205

It is fundamentally impossible for you find that out.

Upvotes: 4

Related Questions