Results 1 to 5 of 5

Thread: PHP - Get Current URL

  1. #1
    Code-aholic conor's Avatar
    Join Date
    Nov 2008
    Location
    Monaghan
    Posts
    60
    Post Thanks / Like

    Default PHP - Get Current URL

    Hi,

    I am trying to find out the current URL using PHP. This is what I have thus far:

    $http = 'http';
    if($_SERVER["HTTPS"] == "on"){
    $http .= "s";
    }
    $http .= "://";
    $url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    $_SESSION['siteurl'] = $http.$url;

    I can't figure out how to take the filename from that. So for example it would currently return:
    http://somesite.com/blah/file.php
    Where as I want it to return:
    http://somesite.com/blah/

    Does anyone know how I could achieve this?

  2. #2
    Code-aholic conor's Avatar
    Join Date
    Nov 2008
    Location
    Monaghan
    Posts
    60
    Post Thanks / Like

    Default

    I just figured it out!

    $http = 'http';
    if($_SERVER["HTTPS"] == "on"){
    $http .= "s";
    }
    $url = $http."://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    $filename = explode("/", $url);
    for( $i = 0; $i < (count($filename) - 1); ++$i ) {
    $_SESSION['siteurl'] .= $filename[$i].'/';
    }

  3. #3
    Frontpage User
    Join Date
    Jul 2008
    Posts
    21
    Post Thanks / Like

    Default

    $_SERVER['PHP_SELF'] should give you the filename...

  4. #4
    Code-aholic conor's Avatar
    Join Date
    Nov 2008
    Location
    Monaghan
    Posts
    60
    Post Thanks / Like

    Default

    yeah but I didn't want the filename. I wanted the URL minus the filename. The code above gives me that

  5. #5
    Frontpage User
    Join Date
    Jul 2008
    Posts
    21
    Post Thanks / Like

    Default

    Just to finish off this thread...

    I've since come across the function Conor was looking for so...

    --------------------------------------------------

    $_SERVER['PHP_SELF'] returns the current file including directory

    dirname($_SERVER['PHP_SELF']) will return the directory only and not include the filename

Similar Threads

  1. New blog - current or new domain
    By EdenWeb in forum Online Marketing Discussion
    Replies: 2
    Last Post: 25-07-2007, 10:05 AM
  2. Keyword links to current page
    By Martina in forum Search Engine Optimisation
    Replies: 6
    Last Post: 28-06-2007, 03:54 PM

Visitors found this page by searching for:

php current folder url

php get current url

php get current url folder

php get current url without filename

php5 get url

php current url without filename

php url folder

php current directory url

php get url folder

php5 current url

php current url folder

php get current folder url

PHP POST current URL

php current url

php get current url dir

php current url directory

php5 get current url

get current url php

php url to current directoryphp 5 get current urlphp get current url directoryphp get current url filenamecurrent directory URL phpphp url current directoryphp current url dir

Tags for this Thread

Posting Permissions

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