SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_SERVER problems

    This is a pretty simple problem, but im getting myselft confused...

    i want to get the name of the page that i am on... so for example:

    if i am on
    http://www.mysite.com/page.php?id=12&y=15

    i want to be able to extract:
    page.php?id=12&y=15

    Now i test my pages on IIS but my live server is Apache

    now ive tried SCRIPT_FILENAME and SCRIPT_NAME

    on IIS SCRIPT_FILENAME gives me undefines variable and SCRIPT_NAME gives me the whole path ie: /php/home/myfile.php

    on Apache SCRIPT_FILENAME gives me the whole path and SCRIPT_NAME gives me +- what i want /myfile.php (i just have to get rid of the / ).

    So...to get
    page.php?id=12&y=15
    from
    http://www.mysite.com/page.php?id=12&y=15

    i need to do the following:
    get SCRIPT_NAME (/page.php)
    $page = remove the / (using ereg replace)
    get QUERY_STRING
    make the string: $page."?".QUERY_STRING

    This should work on Apache right? or is there a better way of doing it? cause this seems like a lot of work for something which should be quite easy?

  2. #2
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok. well here is was i did for anyone interested. I was making it so that if someone goes to a page before they are logged in they will be redirected to that page again after login:
    Code:
    $page = $_SERVER['SCRIPT_NAME']; 
    $page = substr($page,1);
    
    if(isset($_SERVER['QUERY_STRING'])&&($_SERVER['QUERY_STRING']!="")){
    	$page = $page."?".$_SERVER['QUERY_STRING'];
    }
    	$_SESSION['redirect'] = $page;
    	echo $_SESSION['redirect'];
    Works in apache


Bookmarks

Posting Permissions

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