0

I'm using $_SERVER['REMOTE_ADDR'] on 2 separate occassions in 2 php files. The user clicks a link to file a feedback ticket. One php file is created which fills information into an XML file. Later on, the final php file takes the user's IP and puts it into an email for the ticket.

For the email, $_SERVER['REMOTE_ADDR'] works perfectly, but trying to place $_SERVER['REMOTE_ADDR'] into a child in the XML file does not at all.

The tags in the XML file are all functional minus the ip one.

$ticket->addChild('ip', $_SERVER['REMOTE_ADDR']);
$ticket->addChild('ticketid', $ticketid);
$ticket->addChild('call', $post_body);

the ip tag returns nothing as a whole for the tag. If I replace $_SERVER['REMOTE_ADDR'] with just a generic "hello", it makes <ip> hello </ip>. If I place $_SERVER['REMOTE_ADDR'] in it, there's no IP address and the <ip> tags disappear completely.

Google and searches on stackoverflow haven't provided clarity.

JoeL
  • 710
  • 4
  • 18
  • http://stackoverflow.com/questions/10982277/serverremote-addr-not-giving-the-right-ip-address – s.d.a.p.e Mar 30 '15 at 20:15
  • I did see this link previously, but it still doesn't answer for my specific situation why the tags in the XML would be eaten up completely by this request. The user in that question didn't get the IP address he was looking for but he still GOT something. – JoeL Mar 30 '15 at 20:23
  • Code works fine for me! Please make sure you show us your **full** and **real** code! Also make an example with input, current output and expected output – Rizier123 Mar 30 '15 at 20:29
  • @Rizier123 I'll edit as much of the real code into my post as I can since this is involving a company project. There really isn't too much more to it. The user clicks a link to submit feedback. The PHP file writes information from the user's page (upon clicking the link to submit feedback) to an XML file so we know what the specific conditions in the code were that warranted a feedback submission. The next page is where the user writes comments about what he/she experienced and clicks submit. Upon clicking submit, another php file runs that puts a working IP address grab in the email we get. – JoeL Mar 30 '15 at 20:36
  • Well also make sure you add en example file with input, then after your script the output and what you would expect it to end up – Rizier123 Mar 30 '15 at 20:38
  • Ran a test file with the exact code I pasted (minus some important values for my end) and pasted the XML result. – JoeL Mar 30 '15 at 20:46
  • @Rizier123 I think it may ahve just been possible that files were cached or something but I've been trying this with the same file for the past 2 hours and it didn't work when I first made this question here, but for whatever reason it NOW works. But I promise you the syntax did not change. :< Sorry for wasting your time. Thanks for the help though :) – JoeL Mar 30 '15 at 20:48
  • @JoeL :D At least now it works, right ?! – Rizier123 Mar 30 '15 at 20:51
  • @Rizier123 true! However, it still doesn't explain why it would make the ip tag disappear completely. I tried swapping $_SERVER['REMOTE_ADDR'] into the $ticketid spot before I came here just to see if maybe I was doing something wrong with the ip tag. Instead of making the $ticketid tag disappear... It turned it into , again, for reasons I don't know. – JoeL Mar 30 '15 at 20:53
  • You wrote in your question: *" the `` tags disappear completely."* this can never be the case. You perhaps mean that they are empty. This *can* be the case if `$_SERVER['REMOTE_ADDR']` contains an empty string or is just not set (-> [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/367456)) and it's a perfectly fine scenario. Now I hear you moaning about why it's not set. Well that would be the *correct* question if you knew it isn't set. Is it set or not? What does `var_dump($_SERVER);` give? – hakre Mar 30 '15 at 21:14

0 Answers0