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.

Please Clarity these 2 simple doubts in PHP..!

Discussion in 'PHP' started by actress143, Jun 7, 2010.

  1. #1
    I am very fresh to PHP...,

    if you consider the following statement..

    echo "Your IP Address is " . $_SERVER['REMOTE_ADDR'];



    it prints my ip but.., if i change to



    ---> echo "Your IP Address is . $_SERVER['REMOTE_ADDR']";
    then to
    ----> echo "Your IP Address is " $_SERVER['REMOTE_ADDR'];

    it showing errors...,





    whats wrong..

    > i need to know what is the importance of dot ( . ) before $_SERVER['REMOTE_ADDR'];
    > why statement 1 ( echo "Your IP Address is . $_SERVER['REMOTE_ADDR']"; ) is wrong



    Please give good explanation as i am very new to PHP..,

    thanks friends..!
     
    actress143, Jun 7, 2010 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    dot (.) is a string operator to concatenate
    you can also do comma (,) in echo macro
    like
    ---> echo "Your IP Address is ", $_SERVER['REMOTE_ADDR'];
     
    gapz101, Jun 7, 2010 IP
  3. SwedBo

    SwedBo Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Because PHP manual shows you that an array should be wrapped into curly brackets ( { } ) ? :)

    echo "IP: {$_SERVER['REMOTE_ADDR']}";
    PHP:
     
    SwedBo, Jun 7, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    ^^ any variable can also be wrapped
     
    gapz101, Jun 7, 2010 IP
  5. SwedBo

    SwedBo Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    We are talking about arrays here, not just variables. Can and should doesn't mean the same in the context of what he asked / I replied.
     
    SwedBo, Jun 7, 2010 IP
  6. actress143

    actress143 Peon

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    $_SERVER['REMOTE_ADDR'], was this array or varialbe...., why,

    <?php
    $a = 10;
    echo " this is $a "
    ?>

    prints ----> this is 10

    But why not

    <?php
    echo " $_SERVER['REMOTE_ADDR']";
    ?>
     
    actress143, Jun 7, 2010 IP
  7. SwedBo

    SwedBo Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Read the PHP documentation:
     
    SwedBo, Jun 7, 2010 IP
  8. actress143

    actress143 Peon

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ya ya i got.., dear thanks for your help SwedBo,

    and thanks SwedBo and gapz101.
     
    actress143, Jun 7, 2010 IP
  9. Napoleon

    Napoleon Peon

    Messages:
    732
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You can use this:
    echo "Your IP Address is $_SERVER[REMOTE_ADDR]";
     
    Napoleon, Jun 7, 2010 IP
  10. actress143

    actress143 Peon

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ya its working...!, thanks but friends
    why this was not working if we put single quotes in it like

    echo "Your IP Address is $_SERVER['REMOTE_ADDR']";
     
    actress143, Jun 7, 2010 IP
  11. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #11
    1. Dot joins the Output of PHP Variable with a Text precedes that
    See my signature
    2. The Text should be separated from a Variable
    Also If you're going to use $_SERVER[REMOTE_ADDR] for detecting IP its not advised because it returns Proxy's IP when your using Proxy
    So indeed i have a Algorithm for detecting a Real IP
    If you need just Ping me (It hides in my HP NoteBook somewhere else so only)
     
    roopajyothi, Jun 8, 2010 IP
  12. actress143

    actress143 Peon

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Oops..! upto now i believe $_SERVER[REMOTE_ADDR] will gives the original ip......, but i need to get real ip..., if you have the algorithm please PM i really required this...!
     
    actress143, Jun 8, 2010 IP
  13. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #13
    Oops!
    I hope it went into MacBook
    So i have no other way
    but i built using the algorithm written here
    http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html

    Sorry! :)
     
    roopajyothi, Jun 8, 2010 IP
  14. actress143

    actress143 Peon

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Ya its ok, thanks for that link friend..!
     
    actress143, Jun 8, 2010 IP
  15. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #15
    Learning PHP is ease!
    If you run into issues Google that and post here too
    You can get your stuffs enriched easily
    Minimum i will Google 100+ times a Day
     
    roopajyothi, Jun 9, 2010 IP