1

My PHP/HTML/Javascript skills are 0 but I have managed to create a site using a default template which I have modified.

What I am trying to accomplish is to have the browser print out the Cookie Name and Value if it exists. This is for a lab exercise that I'm currently working on. The lab itself is not how you program but rather how you configure Cookie Persistence and as part of the lab I want the student to easily display the cookie on the webpage.

Previous examples have been with HTML/JavaScript and the following code:

<script language="javascript">
function showCookieLink() {
var ele = document.getElementById("CookieLink");
ele.style.display = "block";
} 
</script>
<BODY bgColor="#0066FF" onload="javascript:if (document.cookie) showCookieLink()">
    <tr>     
       <td colspan="2" align="center" vAlign="top">      
        <font face=Arial>
          <div id="CookieLink" style="display: none;"><a href="index.html"     onclick="alert('Cookie = ' + document.cookie); return false;"><b><font color=#0000f0>Display Cookie</b></a></div>
        </font>
       </td>
    </tr>

This previous example have been brilliant. It will print out the clickable link "Display Cookie" (if a cookie exists) and when clicked it will pop up a new smaller window with the Cookie Name and Value.

For some reason this does not work anymore. I have tried several different browsers but they all act the same. JavaScript is enabled on the user.

I have been trying different types of preformatted-codes to fix this but none work (or I just suck at programming/scripting).

Can you guys please help me with this? Perhaps you can print out an example code that I can copy/paste into my current php code?

Thanks in advance!

Philip.J
  • 29
  • 1
  • 5
  • Hey everyone! After I googled a bit more I read about HTTPOnly cookies. Apperantly with the product I'm working with they have automatically added this function to the Cookie Persistence setting in the newest version and I did not notice this. When disabling the HTTPOnly Cookies in the persistence profile the code worked like it was supposed to. Perhaps we can remove this question? – Philip.J Apr 12 '17 at 13:47

1 Answers1

0

According to this post, document.cookies will only work in a web server, not in just html that is served up from the file system. Does your url look like http://localhost or file:///your/file/here.html? It should look like the http:// one.

You also have some issues with your code. you dont close the second font tag, <script> should either be in a <head> or <body> tag, your <body> tag shouldn't be capitalized. Look here for a basic template.

Community
  • 1
  • 1
Brendan Goggin
  • 2,061
  • 14
  • 14