ahvceo Posted May 18, 2009 Share Posted May 18, 2009 Hi All, I am 72 and just starting to learn php. I am having a problem with the "$ref = $HTTP_COOKIE_VARS["ref"];" statement so I tried to see what was being returned in $ref. I see nothing if I do an "echo" (I never have seen echo output anything I could see!) so I thought I would write $ref out to a file. The server pukes at the fopen statement at line 57 (where the fopen statement is) with the following error message: " Parse error: syntax error, unexpected T_IF in /home/ahventur/public_html/user/cookie.php on line 57" I copied and pasted the code for writing to a file directly from a tutorial and I have checked several other sources and all say the same thing. The code is right I think. Can someone tell me how to get at the $ref contents so I can see what is being returned by $HTTP_COOKIE_VARS["ref"]. I would like to be able to use the fopen and fwrite functions for future reference. Any help would be appreciated greatly. Thanks ahvceo code follows: $ref = $HTTP_COOKIE_VARS["ref"]; echo $ref; $f = xyz.txt if (!$handle = fopen($f, 'w')) { echo "Cannot open file ($f)"; exit; } if (fwrite($handle, $ref) === FALSE) { echo "Cannot write to file ($filename)"; exit; } Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 18, 2009 Share Posted May 18, 2009 Wow 72? $f = xyz.txt That should be: $f = 'xyz.txt'; You need quotes. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted May 18, 2009 Share Posted May 18, 2009 Very inspiring thread, at 72! thats fantastic, hopefully you will in no time become a great programmer. when you usually have a unexpected something, syntax error, go to the lines before line 57" and see if you have a ";" after each line of code. and as Ken mentioned, fopen args for the file name has to be quoted Quote Link to comment Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 72. I'm very impressed. It's very refreshing to see someone of your age to be interested in new ideas and willing to open his mind and learn new things. I wish you the best of luck with your PHP programming! Quote Link to comment Share on other sites More sharing options...
ahvceo Posted May 18, 2009 Author Share Posted May 18, 2009 Hi Guys, Thanks for all the good cheer! The only thing being wrong with being 72 is your memory isn't as good and you have trouble with tiny details. There was one other thing that I lost some time ago but I can't remember what it was. Well the server is no longer puking on my code thanks to your help. I run the code with no errors. The only problem is I cannot find the file! Where in the XXXX does it go? I have changed the code slightly as follows $ref = $HTTP_COOKIE_VARS["ref"]; echo $ref; $f = 'xyz.txt'; $today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm if (!$handle = fopen($f, 'w')) { echo "Cannot open file ($f)"; exit; } if (fwrite($handle, $ref) === FALSE) { echo "Cannot write to file ($filename)"; exit; } if (fwrite($handle, $today) === FALSE) { echo "Cannot write ($today)"; exit; } fclose($handle); I added a write time statement so I would know if the file was really being written when I though it should be and I added a fclose statement because I remember form somewhere that you need to close a file before it really wirite it out. I also tried to put a path in the file namer(C:\xyz.txt) to see if I could find it on my C drive, No Luck. Any ideas where the file might be going of how I find out if it is being written at all? Thanks ahvceo Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 18, 2009 Share Posted May 18, 2009 1. Please try to remember to use tags when posting codes. 2. You're trying to use PHP to write to a file on your computer? Quote Link to comment 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.