WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $_server (script uri, query string, etc) - unable to retieve (8 posts)

  1. JRPereira
    Member
    Posted 8 years ago #

    For some reason or another I can't seem to access (just returns blank) $_SERVER variables to use with my stats system - it's only been happening since I started using wordpress, and I've made sure to clear any rewrites/etc out of my .htaccess and the httpd.conf itself. WordPress appears to be doing something with those variables (with varying things like the REMOTE_ADDR being available depending on where I require() the stats update code (which basically just tosses up another row in a mysql table.

    Since I'm not really sure what wordpress is doing, I'm kind of at a standstill scratching my head and wondering what to do.

  2. JRPereira
    Member
    Posted 8 years ago #

    Uh woops can somebody move this topic to the right subforum?

  3. jalenack
    Member
    Posted 8 years ago #

    This may have something to do with WordPress's deregistering globals. Are you trying to access them like $REMOTE_ADDR? That would do it. Try using the normal way of $_SERVER['REMOTE_ADDR'] ...

    Also, you could try adding print_r($_SERVER) and seeing if there's any data there.

    Cheers

  4. JRPereira
    Member
    Posted 8 years ago #

    I tried both $remote_addr and $_server['remote_addr'] - I'll try print_r and see what happens.

  5. JRPereira
    Member
    Posted 8 years ago #

    This is the result: Looks like script URI no longer exists, along with a few other things. It's enough to work with, so thanks a ton, but I have to say it's odd that some of the variables are being completely erased.

    Array
    (
    [DOCUMENT_ROOT] => /home/wwu/public_html/justinpereira
    [HTTP_ACCEPT] => image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [HTTP_ACCEPT_LANGUAGE] => en-us
    [HTTP_CONNECTION] => Keep-Alive
    [HTTP_COOKIE] => [REMOVED BY JRPEREIRA] [REMOVED BY JRPEREIRA]
    [HTTP_HOST] => http://www.justinpereira.com
    [HTTP_REFERER] => http://www.justinpereira.com/
    [HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
    [PATH] => /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
    [REDIRECT_QUERY_STRING] => page_id=283
    [REDIRECT_STATUS] => 200
    [REDIRECT_URL] => /
    [REMOTE_ADDR] => 216.127.136.54
    [REMOTE_PORT] => 2788
    [SCRIPT_FILENAME] => /home/wwu/public_html/justinpereira/index.php
    [SERVER_ADDR] => 67.15.12.66
    [SERVER_ADMIN] => webmaster@justinpereira.unleashed.ws
    [SERVER_NAME] => http://www.justinpereira.com
    [SERVER_PORT] => 80
    [SERVER_SIGNATURE] =>
    [SERVER_SOFTWARE] => Apache
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => page_id=283
    [REQUEST_URI] => /?page_id=283
    [SCRIPT_NAME] => /index.php
    [PATH_TRANSLATED] => /home/wwu/public_html/justinpereira/index.php
    [PHP_SELF] => /index.php
    [argv] => Array
    (
    [0] => page_id=283
    )

    [argc] => 1
    )

  6. JRPereira
    Member
    Posted 8 years ago #

    By the way, thanks a TON for showing me the print_r function.

  7. jalenack
    Member
    Posted 8 years ago #

    Remember, the $_SERVER global must be in ALL CAPS. And so do it's children like REMOTE_ADDR. Saying $_SERVER['remote_addr'] will turn up nothing

    Aye, that print_r() is a handy one. There's also var_dump(), but I usually find that you can get the info needed from print_r.

    Also, when I'm debugging, I've got this little function called echo_r(). It does the same thing as print_r() except it wraps it in <pre> tags.

    function echo_r($array) {
    echo "<pre>";
    print_r($array);
    echo "</pre>";
    }

    That allows me to see the array nice and formatted.

    Cheers

  8. tomkinsg
    Member
    Posted 7 years ago #

    I have a similar issue to this ... I have my print_r within a post using RunPHP.

    In my case i can see the output of the print_r shows that query_string is null even though my URI that i called the page with includes a query string. lots of the other values are being returned.

    My URI: http://localhost/wordpress/blog/category/sidebar/register/?var=value

    result of the print_r:

    Array
    (
    [HTTP_HOST] => localhost
    [PATH] => C:\Program Files\Windows Resource Kits\Tools\;C:\Program Files\ThinkPad\Utilities;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\IBM\Infoprint Select;C:\Notes;C:\Program Files\XLView;C:\lotus\compnent;C:\Utilities;C:\Program Files\IBM\Personal Communications\;C:\Program Files\IBM\Trace Facility\;C:\Program Files\ThinkPad\ConnectUtilities;C:\WINDOWS\Downloaded Program Files;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\ATI Technologies\ATI Control Panel
    [SystemRoot] => C:\WINDOWS
    [COMSPEC] => C:\WINDOWS\system32\cmd.exe
    [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    [WINDIR] => C:\WINDOWS
    [SERVER_SIGNATURE] =>
    Apache/2.2.3 (Win32) DAV/2 mod_ssl/2.2.3 OpenSSL/0.9.8c mod_autoindex_color PHP/5.1.6 Server at localhost Port 80

    [SERVER_SOFTWARE] => Apache/2.2.3 (Win32) DAV/2 mod_ssl/2.2.3 OpenSSL/0.9.8c mod_autoindex_color PHP/5.1.6
    [SERVER_NAME] => localhost
    [SERVER_ADDR] => 127.0.0.1
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 127.0.0.1
    [DOCUMENT_ROOT] => C:/xampplite/htdocs
    [SERVER_ADMIN] => admin@localhost
    [SCRIPT_FILENAME] => C:/xampplite/htdocs/register.php
    [REMOTE_PORT] => 4340
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.0
    [REQUEST_METHOD] => GET
    [QUERY_STRING] =>
    [REQUEST_URI] => /register.php
    [SCRIPT_NAME] => /register.php
    [PHP_SELF] => /register.php
    [REQUEST_TIME] => 1160425108
    [argv] => Array
    (
    )

    [argc] => 0
    )

    in the header.php in my theme, i can see the var=value but in the page template page.php, the value is cleared.

    suggestions appreciateed. thanks
    Glyn

Topic Closed

This topic has been closed to new replies.

About this Topic