Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Decode JSON from a RESTful request

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 4543 Views
  • ccburns
    Avatar
    Community Member
    74 Posts

    Decode JSON from a RESTful request Link to this post

    Hi All,

    I maybe silly doing it this way and please if you have a better suggestions I would love to hear it...

    I am trying to get the Remote IP address, but the native PHP $_SERVER variable are not giving me the information that I need to work out the clients country.

    Basically I am building a site for a .com.au company and they want to either tell their .co.nz customers that they should be going to the .co.nz site not the .com.au site (hope that makes sense).

    So I am trying to get the users IP address but it is always coming back as 192.168.*.* etc because they are behind routers etc.

    I have found a site that returns a JSON value for the IP address that has been correct each time I have tried it and a friend in NZ has also tried.

    http://jsonip.appspot.com/

    Anyway, I notice that http://doc.silverstripe.org/restfulservice doesn't support JSON. Is there any way for me to get this information into a variable so I can feed it into my other function that pulls back the country of the IP address...

    Any suggestions?

    Thanks in advance,
    Colin

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Decode JSON from a RESTful request Link to this post

    Not sure if this helps, but you could always use the PHP json_decode function to convert JSON encoded values into PHP objects/variables.

    4543 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.