SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTTP + Ip address

    Could anyone tell me why when i put the following code to the function it won't work ?

    it never return the client ip address , but if i didn't put it as separete file then it will work

    here is the main.php

    <?
    include ("authority.inc");
    ?>



    and here is the authority.inc which contain the following function.


    <?
    function validateUser()
    {
    $IPaddress=$HTTP_SERVER_VARS{'REMOTE_ADDR'};
    echo $IPaddress;
    }
    ?>


    Thanks in advance
    signature

  2. #2
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The main file should look like this:

    Code:
    <? 
    include ("authority.inc"); 
    validateUser();
    ?>
    authority.inc will remain the same:

    Code:
    <? 
    function validateUser() 
    { 
    $IPaddress=$HTTP_SERVER_VARS{'REMOTE_ADDR'}; 
    echo $IPaddress; 
    } 
    ?>
    signature

  3. #3
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTTP + IP

    Sorry, yeah,, my main file is like the one u wrote,
    i just forgot to type validateUser();

    but, it still doesn't work,,,, and even give the warning.....

    any idea ???

    is it because some php engine doesn't enabled ??







    The main file should look like this:



    code:
    --------------------------------------------------------------------------------

    <?
    include ("authority.inc");
    validateUser();
    ?>


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



    authority.inc will remain the same:


    code:
    --------------------------------------------------------------------------------

    <?
    function validateUser()
    {
    $IPaddress=$HTTP_SERVER_VARS{'REMOTE_ADDR'};
    echo $IPaddress;
    }
    ?>
    signature

  4. #4
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correct me if I'm wrong but this:
    PHP Code:
    <? 
    function validateUser() 

    $IPaddress=$HTTP_SERVER_VARS{'REMOTE_ADDR'}; 
    echo 
    $IPaddress

    ?>
    Should be this:

    PHP Code:
    <? 
    function validateUser() 

    $IPaddress=$HTTP_SERVER_VARS['REMOTE_ADDR']; 
    echo 
    $IPaddress

    ?>
    Notice the use of [ and not {
    Oh no! the coots are eating my nodes!

  5. #5
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTTP + IP

    nope it doesn't work, today i just knew that, if it is passed to the function u need to use
    global $HTTP_SERVER_VARS;

    otherwise it will return nothing...

    By the way, does anyone have idea without using the global variable ?

    since the solution given above is doesn't work...



    Any way

    Thanks for the help yeah.... sorry for asking too much.. i just learnt php for 3 days ..... really a new beginner...
    Last edited by starix; Sep 4, 2001 at 02:04.
    signature

  6. #6
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not working because the function validateUser() calling $HTTP_SERVER_VARS['REMOTE_ADDR'] is in an include file.

    I imagine that you're going to do a lot more in validateUser() than just echo the ip address. My suggestion to you is that you pass it.

    PHP Code:

    /* In authority.inc */
    function validateUser($ipAddress) {
      
    //manipulations with $ipAddress
    }


    /* In main file */
    validateUser($HTTP_SERVER_VARS['REMOTE_ADDR']); 

  7. #7
    SitePoint Enthusiast kcabobert's Avatar
    Join Date
    Aug 2001
    Location
    Topeka, KS
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe I missed the point, but why not just
    PHP Code:
    <?
    echo("$REMOTE_ADDR");
    ?>
    That always seems to work for me, or in a function:
    PHP Code:
    <?

    function validateUser() {
    echo(
    "$REMOTE_ADDR");
    // other stuff

    }
    /* or if it just collects information about the user */

    function validateUser() {
    $userinfo "The user was using: ".$HTTP_USER_AGENT."\n IP: ".$REMOTE_ADDR."\n They Came From: ".$HTTP_REFERER;

    // other stuff
    return $userinfo;
    }

    ?>
    Like I said I may have not understood what you were trying to do. Then include that file at the top of the page and to use the function: <?echo("validateUser()");?> unless it echos it inside the function. Also if the function echos something and you call it before <html>.....<body> it may give errors.
    Microsoft's Motto: Resistance is futile, you will be assimilated.

    My dog's name is Jade; she is a Miniature pinscher.
    Click here to see some of her pictures

  8. #8
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i always like to use this when grabbing an ip address:
    PHP Code:
    // Get user's ip
    if (getenv(HTTP_CLIENT_IP)){ 
    $user_ip=getenv(HTTP_CLIENT_IP); 

    else { 
    $user_ip=getenv(REMOTE_ADDR); 

    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  9. #9
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This isn't an issue on HOW he's getting the client's ip address. I agree, both of your suggestions work fine doing just that.. and so does his.

    Read his original question thoroughly before posting your answers. It's the environment of the include file that's causing the problem. A solution to this has already been posted.

  10. #10
    SitePoint Enthusiast kcabobert's Avatar
    Join Date
    Aug 2001
    Location
    Topeka, KS
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    read the bottom of my post. I did mention about the include and possible problems. This is not the place to gripe at each other. It is to help each other learn new, possibly better or diffrent ways, of doing things.
    Last edited by kcabobert; Sep 5, 2001 at 21:05.
    Microsoft's Motto: Resistance is futile, you will be assimilated.

    My dog's name is Jade; she is a Miniature pinscher.
    Click here to see some of her pictures

  11. #11
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jees, cupid, i was just providing alternative ways of doing things.
    ain't gotta bite my head off.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  12. #12
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry guys, I didn't mean to offend either of you.

    In my last post, I praised your solutions for getting the remote host address. I just thought your answers were a little misleading. I'll be careful of how I word things in my future posts.
    Last edited by cupid; Sep 5, 2001 at 21:20.

  13. #13
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no offense taken, but i did mention that what i posted was just another way to grab the users ip.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  14. #14
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    http+IP

    oK guys....
    its enough...
    i find my solution by using global....
    i just want to know whether there is anotheway..for doing it..

    yeah...
    in validateUser()
    i'll do the checking the ip address subsitute to the validateUser($ip);
    then compare the username and password to the databases....
    and this should be can be use by anyone....

    Thanks any guys.. don't argue anymore yeah
    signature


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
  •