Get last page only!

Discussion in 'PHP' started by badmasketa, Oct 7, 2008.

  1. #1
    badmasketa, Oct 7, 2008 IP
  2. lruneh

    lruneh Peon

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try
    $_SERVER['PHP_SELF']
    Code (markup):
    That should return the part that you are looking for.
     
    lruneh, Oct 7, 2008 IP
  3. Sillysoft

    Sillysoft Active Member

    Messages:
    177
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I believe that just returns the path itself, not the query portion of the url:

    Long way:

    
    
    $current_url = parse_url($_SERVER['REQUEST_URI']);
    	
    $url_path = trim($current_url['path']);
    $url_query = trim($current_url['query']);
    $url_query = (!empty($url_query)) ? '?' .$url_query : $url_query;
    	
    $url = $url_path .$url_query;
    
    
    PHP:
    Short way:

    
    
    $url_path = trim($_SERVER['PHP_SELF']);
    $url_query = trim($_SERVER['QUERY_STRING']);
    $url_query = (!empty($url_query)) ? '?' .$url_query : $url_query;
    	
    $url = $url_path .$url_query;
    
    
    PHP:
     
    Sillysoft, Oct 7, 2008 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    
    $url = 'http://www.kanchan.com.np/events.php?id=1&image_id=20#test';
    $info = parse_url($url);
    echo $info['path'].'?'.$info['query'].'#'.$info['fragment'];
    
    PHP:
    Peace,
     
    Barti1987, Oct 7, 2008 IP
  5. lruneh

    lruneh Peon

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ofcourse you're right - I'm retarded...

     
    lruneh, Oct 8, 2008 IP