SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2001
    Location
    home
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getenv function and register_globals

    I have a recommend page script on my site that uses:

    IF ($action=="") {
    $referer = getenv("HTTP_REFERER");
    print "<p><B>URL to refer/B>&nbsp; <font color=\"#FF0000\">".$referer."</font><BR><BR></p>


    ....however, I noticed that it no longer works. I believe it has to do with the fact that register_globals is turned off in my PHP configuration. Is there a way to get around this so that this function will work?

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Your code should look like:

    PHP Code:
    if($action == "")
    {
    $referer $_SERVER['HTTP_REFERER']; 

  3. #3
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not recommended, but if all of your scripts are written like this, you could hack it with .htaccess:

    PHP Code:
    php_flag register_globals ON 
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  4. #4
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Here is some code to assign the variables if there is an older version of PHP on a different server. This will allow you to keep your code and not have to keep modifying it for different servers because of the variable differences. (Thanks to seanf for the code).
    PHP Code:
    if ( !isset ( $_GET ) ) { $_GET $HTTP_GET_VARS; } 
    if ( !isset ( 
    $_POST ) ) { $_POST $HTTP_POST_VARS; } 

  5. #5
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd use
    PHP Code:
    if (!isset($_GET)) $_GET =& $HTTP_GET_VARS;
    if (!isset(
    $_POST)) $_POST =& $HTTP_POST_VARS;
    if (!isset(
    $_COOKIE)) $_COOKIE =& $HTTP_COOKIE_VARS;
    if (!isset(
    $_SERVER)) $_SERVER =& $HTTP_SERVER_VARS;
    if (!isset(
    $_FILES)) $_FILES =& $HTTP_POST_FILES
    you could also do $_SESSION, and create a $_REQUEST array from GET, POST, and COOKIE.

    (Note, you will still need to call global $_* in functions in earlier versions, as these arrays weren't super globals)
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


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
  •