# Location of current PHP file

**URL:** <https://forum.kirupa.com/t/location-of-current-php-file/262433>\
**Category:** Uncategorized\
**Created:** [June 5, 2008, 9:34pm UTC](https://forum.kirupa.com/t/location-of-current-php-file/262433 "2008-06-05T21:34:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [June 5, 2008, 9:34pm UTC](https://forum.kirupa.com/t/location-of-current-php-file/262433/1 "2008-06-05T21:34:57Z")

</div>

I will be storing identical copies of index.php in _[www.site.com/english](http://www.site.com/english)_ and _[www.site.com/czech](http://www.site.com/czech)_. Is there anyway for index.php to determine which folder (language) it is in? I would like either “english” or “czech” returned.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 5, 2008, 10:39pm UTC](https://forum.kirupa.com/t/location-of-current-php-file/262433/2 "2008-06-05T22:39:00Z")

</div>

```php

echo getcwd();

```

---

<div class="post-metadata">

**Author:** ![k77](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@k77](https://forum.kirupa.com/u/k77)\
**Post date:** [June 5, 2008, 10:43pm UTC](https://forum.kirupa.com/t/location-of-current-php-file/262433/3 "2008-06-05T22:43:02Z")

</div>

Using a cookie. Using a conditional statement or better using a member setting with a database connection which is in the member cp, so if user checks the box, it adds CZECH record in the database to 1 and then when logged in return 1?? Or conditional… new to php myself but…

```php

    while ($row = $result->fetch_assoc()) 
    {
		printf("index.php?lang="'.$row['Lang']).'");
    } else {
		include "langpicker_dropdown_html_snippet_or_check_box.inc";
    // return the list
    return $myLang;
  }

```

Anyone can correct me

---

<div class="post-metadata">

**Author:** ![djheru](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/djheru/32/3190_2.png) [@djheru](https://forum.kirupa.com/u/djheru)\
**Post date:** [June 6, 2008, 3:56am UTC](https://forum.kirupa.com/t/location-of-current-php-file/262433/4 "2008-06-06T03:56:52Z")

</div>

The best way to do it would be to use patinfo()

```php

$path = $_SERVER['PHP_SELF']; //something like /var/www/sitename/czech/index.php
$split_path = pathinfo($path); //Creates associative array of parts
$language = substr(strrchr($split_path['dirname'],'/'),1); //should give you 'czech' 

```
