Hi, I have been given a php assignment, and i just can't do it. I have created a welcome page which starts with as prompt box asking for the user's name, and then displays how many times the user has visited the site. I have used javascript to create a cookie, but I need access the cookie using php. Is there a way to do this, and if there is, how?

Basically, the next task is to create hyperlinks and display them in the order of most clicked. I have no idea how to do this, so any suggestions would also be appreciated.

Any replies would be greatly appreciated.

I can be contacted by email
joanne.w@btinternet.com

joanne.w at btinternet dot com (in case my email address didn't appear above)

    Why not just use a PHP cookie? You could collect the data with a normal HTML form that way. Javascript cookies can only be read by Javascript, you'd have to pass the data by URL, which really defeats the purpose of a cookie.

      This is what i have so far, it's called Attempt3.html, I would use PHP, but i don't know how to, i have looked it up, but i can't find anything that does what i want (check for cookie; if no cookie ask for email address; if there is a cookie, welcome user; tell user how many times they have visited)

      <html>

      <head><script LANGUAGE="JAVASCRIPT"">

      <!--//

      / ####################### start set cookie ####################### /

      function setCookie(name, value) {

      var thisCookie = name + "=" + escape(value) ;
      document.cookie = thisCookie;
      }
      / ####################### start show cookie ####################### /

      function showCookie(){

      alert(unescape(document.cookie));
      }
      / ####################### start get cookie value ####################### /

      function getCookieVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
      endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
      / ####################### end get cookie value ####################### /

      }
      / ####################### start get cookie (name) ####################### /

      function GetCookie (name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
      }
      return null;
      }
      / ####################### end get cookie (name) ####################### /

      / ####################### start delete cookie ####################### /
      function DeleteCookie (name) {
      if (GetCookie(name)) {
      document.cookie = name ;
      }
      }
      / ####################### end of delete cookie ####################### /

      function NewNamer(){
      var now= new Date();
      now.setTime(now.getTime() + 365 24 60 60 1000);
      var name = GetCookie("name");
      if ((!name)||(name=='null'))
      {
      name = prompt("Please enter your email address:", "");
      }
      setCookie("name", name);
      if (name)
      {
      document.write("Hello, "+name+"");

      setCookie("name", name);
      }
      else
      document.write("Welcome to the page, (No name given) "+
      "<a href=\"attempt3.html\" onClick=\"ChangeName();history.go(-1)\">Click here </a>");

      }

      function ChangeName(){
      var name = GetCookie("name");
      name = prompt("Please enter your name:","");
      setCookie("name", name);
      var visits='';
      setCookie("counter", visits);
      NewNamer()}
      / ####################### count visits ####################### /

      function VisitCounter(){
      var visits = GetCookie("counter");
      if (!visits) { visits = 1;
      document.write(", this is your first time here.");
      }
      else {
      visits = parseInt(visits) + 1; document.write(", you have been here " + visits + " times.");}
      setCookie("counter", visits);
      }

      / ####################### end of count visits ####################### /

      //-->
      </script>
      <!-- ####################### ####################### -->
      <script LANGUAGE="JAVASCRIPT">
      <!--//

      function setcookie(){
      document.cookie = 'Cookie Name='+document.form1.cookieName.value;

      }
      function showCookie(){

      alert(document.cookie);
      }
      //-->
      </script>

      </head>
      <!-- ####################### ####################### -->

      <body>

      <p><script language="JavaScript">
      <!--//
      NewNamer()
      VisitCounter()

      //-->
      </script></p>

      <!-- ####################### Show cookie button ####################### -->

      <form name="form1" form method='Post' Action='welcome1.php'>

      <input type="button" value="Show cookie" name="B2" onClick="showCookie()"></p>
      <input type="submit" value="Continue" name="tophp" action='welcome1.php'>
      </form>
      <!-- ##################### End of show button cookie ##################### -->

      <script language="JavaScript">
      var name = GetCookie("name");
      document.write("If you are not "+name+
      ", then <a href=\"attempt3.html\" onClick=\"ChangeName();history.go(-1)\">click here.</a> ");
      </script>

      </body>
      </html>

        All you need to use in PHP is the [MAN]setcookie[/MAN] function and the $_COOKIE superglobal.

          Write a Reply...