1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Showing Visitor IP Address

Discussion in 'PHP' started by ademmeda, Jul 11, 2011.

  1. #1
    Hi,

    I want to show the IP address of the visitor on one post of my blog. The posts are stored in MySQL database and I learned that I will need to use eval() function to make PHP work in the database field. I am using the following code but it doesn't work.

    <?php eval( '?><?php echo $_SERVER['REMOTE_ADDR']; ?><?' ); ?></p>
    PHP:
    Do you have any ideas?
     
    ademmeda, Jul 11, 2011 IP
  2. balaganesh

    balaganesh Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    echo $_SERVER['SERVER_NAME'];
    ?>
     
    balaganesh, Jul 11, 2011 IP
  3. eleetgeek

    eleetgeek Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    eval()? data?
    What software are you using? and if anything is popping out from database, it cannot be PHP script at any cost. Fetched data from database can be ONLY be echo-ed, print, etc it cannot be 'RUN'...
    Mate, you just might want to use
    <?php echo "$_SERVER['REMOTE_ADDR']"; ?>
    PHP:
    On the page where the 'views' displays your post.

    However, Let me know what software you are using and it will help me assist you with 'proper' guidance but, from database, you cannot parse php :)
     
    eleetgeek, Jul 11, 2011 IP
  4. akshat.gl

    akshat.gl Member

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    <?php echo "$_SERVER['REMOTE_ADDR']"; ?> You dont need database to show the ip address of current user. Just add this line anywhere and it will show visitor's ip address :)
     
    akshat.gl, Jul 11, 2011 IP
  5. AdsMakeSense

    AdsMakeSense Active Member

    Messages:
    389
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    70
    #5
    Not sure what you mean, if the IP address is already stored, pull it from the database...
    Otherwise you need to use the Remote Addr and input the IP address when the thread/post is made.
     
    AdsMakeSense, Jul 11, 2011 IP
  6. ademmeda

    ademmeda Active Member

    Messages:
    354
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    70
    #6
    I'm not using any software. This is plain simple PHP-MySQL blog. Posts are stored in the database and simply adding your code into the post where I want to show visitor's IP doesn't work.

    IP address is not stored, I will just show it on that single post.
     
    ademmeda, Jul 12, 2011 IP
  7. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Not stored? then just use this when you need to display visitor's IP.

    <?php echo $_SERVER['REMOTE_ADDR']; ?>

    You don't need eval here.
     
    ads2help, Jul 12, 2011 IP
  8. ademmeda

    ademmeda Active Member

    Messages:
    354
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    70
    #8
    The post is stored in the database and that code doesn't work. That's why I was involved with eval.
     
    ademmeda, Jul 12, 2011 IP
  9. gnomee

    gnomee Greenhorn

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #9
    Create another row in database table where you save posts and save IP from author of post and then when you displaying post include IP row and will be displayed.
     
    gnomee, Jul 12, 2011 IP
  10. ademmeda

    ademmeda Active Member

    Messages:
    354
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    70
    #10
    Ok the issue is solved. I found the answer to my problem: "use iframe".
     
    ademmeda, Jul 12, 2011 IP