marionreview Posted November 1, 2009 Share Posted November 1, 2009 Hi- New to the forum. Please pardon mistakes. I have a form that creates the variables r1, r2, r3 as part of a very simple HTML form. The form then calls a php page that does the following: <?php $myfile = fopen ("outcomes_survey.csv", "a"); $fp = fwrite($myfile,date("Y/m/d").",$_SERVER["REMOTE_ADDR"],$_POST[r1],$_POST[r2],$_POST[r3] "); fclose($myfile); ?> If I take out the code ,$_SERVER["REMOTE_ADDR"] the code works perfectly and write the date and variables to outcomes_survey.csv Can anyone tell me how to fix my code so that it will write the user's IP address? I assume I have a simple syntax error. I have tried using single quotes. Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/179867-solved-request-for-help-writing-_serverremote_addr-as-part-of-an-fwrite/ Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 When using arrays in strings who's indexes are also surrounded by quotes you must use curly braces ({ }) to tell PHP where the variable starts and ends. $fp = fwrite($myfile,date("Y/m/d").",{$_SERVER["REMOTE_ADDR"]},$_POST[r1],$_POST[r2],$_POST[r3] "); In the future you should use [code] or [php] tags, it makes things easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/179867-solved-request-for-help-writing-_serverremote_addr-as-part-of-an-fwrite/#findComment-948854 Share on other sites More sharing options...
redarrow Posted November 1, 2009 Share Posted November 1, 2009 When using arrays in strings who's indexes are also surrounded by quotes you must use curly braces ({ }) to tell PHP where the variable starts and ends. and in php6 {} will be the [] square braces i think? Quote Link to comment https://forums.phpfreaks.com/topic/179867-solved-request-for-help-writing-_serverremote_addr-as-part-of-an-fwrite/#findComment-948855 Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 I'm not quite sure about that, perhaps you're referring to the fact that in PHP6 to access specific characters in strings you'll have to use [ ] vs { }. Quote Link to comment https://forums.phpfreaks.com/topic/179867-solved-request-for-help-writing-_serverremote_addr-as-part-of-an-fwrite/#findComment-948856 Share on other sites More sharing options...
marionreview Posted November 1, 2009 Author Share Posted November 1, 2009 Thank you AlexWD! The suggested code worked! I will include the suggested tags in the future. Quote Link to comment https://forums.phpfreaks.com/topic/179867-solved-request-for-help-writing-_serverremote_addr-as-part-of-an-fwrite/#findComment-948858 Share on other sites More sharing options...
redarrow Posted November 1, 2009 Share Posted November 1, 2009 Yes i was alex, i was thinking that all {} braces, will become [] square braces in php6 Quote Link to comment https://forums.phpfreaks.com/topic/179867-solved-request-for-help-writing-_serverremote_addr-as-part-of-an-fwrite/#findComment-948862 Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 I'm pretty sure that rule only applies to string indexes. Quote Link to comment https://forums.phpfreaks.com/topic/179867-solved-request-for-help-writing-_serverremote_addr-as-part-of-an-fwrite/#findComment-948863 Share on other sites More sharing options...
redarrow Posted November 1, 2009 Share Posted November 1, 2009 yeeeeeeee your correct as usual lol.... Quote Link to comment https://forums.phpfreaks.com/topic/179867-solved-request-for-help-writing-_serverremote_addr-as-part-of-an-fwrite/#findComment-948865 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.