php – How to find the Cookie Value and Session ID-ThrowExceptions

Exception or error:

I am not sure how I am supposed to find the Cookie value and session id. Under what “section” in developer settings am I supposed to navigate to in-order to find this information

Here is the code:

cookie.php

<?php
// Note - cannot have any output before setcookie
if ( ! isset($_COOKIE['zap']) ) {
    setcookie('zap', '42', time()+3600);
}
?>
<pre>
<?php print_r($_COOKIE); ?>
</pre>
<p><a href="cookie.php">Click Me!</a> or press Refresh</p>

nocookie.php

<?php
    // Tell PHP we won't be using cookies for the session
    ini_set('session.use_cookies', '0');
    ini_set('session.use_only_cookies',0);
    ini_set('session.use_trans_sid',1);

    session_start();

// Start the view
?>
<p><b>No Cookies for You!</b></p>
<?php
    if ( ! isset($_SESSION['value']) ) {
        echo("<p>Session is empty</p>\n");
        $_SESSION['value'] = 0;
    } else if ( $_SESSION['value'] < 3 ) {
        $_SESSION['value'] = $_SESSION['value'] + 1;
        echo("<p>Added one \$_SESSION['value']=".$_SESSION['value']."</p>\n");
    } else {
       session_destroy();
       session_start();
       echo("<p>Session Restarted</p>\n");
    }
?>
<p><a href="nocookie.php">Click This Anchor Tag!</a></p>
<p>
<form action="nocookie.php" method="post">
  <input type="submit" name="click" value="Click This Submit Button!">
</form>
<p>Our Session ID is: <?php echo(session_id()); ?></p>
<pre>
<?php print_r($_SESSION); ?>
</pre>

sessfun.php

<?php
  // Note - cannot have any output before this
  session_start();
  if ( ! isset($_SESSION['pizza']) ) {
     echo("<p>Session is empty</p>\n");
     $_SESSION['pizza'] = 0;
  } else if ( $_SESSION['pizza'] < 3 ) {
    $_SESSION['pizza'] = $_SESSION['pizza'] + 1;
     echo("<p>Added one...</p>\n");
  } else {
    session_destroy();
    session_start();
    echo("<p>Session Restarted</p>\n");
  }
?>
<p><a href="sessfun.php">Click Me!</a></p>
<p>Our Session ID is: <?php echo(session_id()); ?></p>
<pre>
<?php print_r($_SESSION); ?>
</pre>

I am not sure how I am supposed to find the Cookie value and session id. Under what “section” in developer settings am I supposed to navigate to in-order to find this information
I am quite new to PHP. PLease answer my question. thank you

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *