2

This issue has been haunting me for a long time, and I haven't been able to solve it.

The following code is part of a basic assignment: the page should record every user access in the form of cookies. I opted for a main cookie that records the number of accesses and several "acc-N" cookies (with timestamp) for each individual access.

<?php
    if(!isset($_COOKIE["numAcc"]))
        $num = 1;
    else
        $num = (int)$_COOKIE["numAcc"] + 1;

    setcookie("numAcc", $num, time() + (86400 * 365), "/"‬);
    setcookie("acc-".$num, date("Y-m-d_H.i.s"), time() + (86400 * 365), "/");
?>

Using XAMPP with PHP 7.3.9, the first "setcookie" causes the following error:

"Parse error: syntax error, unexpected '‬' (T_STRING), expecting ')' in assignment.php on line 7

I have no clue as to what is causing it, the second "setcookie" works fine when the first is commented out.

Rusher
  • 21
  • 2
  • 3
    There is an extra character between the last quote and the close `)` in `setcookie("numAcc", $num, time() + (86400 * 365), "/"‬);`. Try deleting them and re-adding the last part.` – Nigel Ren Dec 01 '20 at 16:31
  • Wow, that did it, thanks a lot. How did you find it? I got a feeling of there being something wrong with the chars, but even Npp with "show all characters" wouldn't show anything suspicious. – Rusher Dec 01 '20 at 16:38
  • 1
    I admit I didn't find it either. I did rewrite the end of the line that fixed it. Not until I saw @NigelRen's comment did I arrow through and find the issue. The character was [POP DIRECTIONAL FORMATTING](https://www.fileformat.info/info/unicode/char/202c/index.htm). Did you copy paste that code from anywhere? – mikeroq Dec 01 '20 at 16:40
  • Don't recall, wrote that assignment almost a year ago, Prof let the error slide since she didn't see any mistake. I might have Copied it from a previous assignment or W3S's PHP Cookie tutorial page. – Rusher Dec 01 '20 at 16:45

0 Answers0