1

I have this PHP code :

<?php
  if(isset($_POST['go'])){
     echo 'the array contains' . $_COOKIE['arrayCount'] . 'values';
  }
?>
<form method='POST'>;
  <?php
    $arr = array(//some dynamic values);
    setcookie('arrayCount' , count($arr));
  ?>
  <input type='submit' name='go' />
</form>

for example if the count of the value in the array is '10' , and the previous count was '15' , I get the '15' printed with the message: 'the array contains 15 values'

I want to print the message at the top of the page , Is it possible to be done this way or I would need to use Ajax or re arrange the code?

Joe
  • 43
  • 7

1 Answers1

0

Per the documentation, not with PHP.

This requires that you place calls to this function prior to any output, including and tags as well as any whitespace.

However, you can get it on the next page load.

Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE array. Cookie values may also exist in $_REQUEST.

However, How do I create and read a value from cookie? has great information on how to do it with Javascript.

kchason
  • 2,836
  • 19
  • 25