aakash2310

Untitled

Aug 17th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. 5.
  2.  
  3. <?php
  4. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  5. $n = $_POST['n'];
  6. $s1 = $_POST['s1'];
  7. $s2 = $_POST['s2'];
  8. $s3 = $_POST['s3'];
  9.  
  10. setcookie('n', $n);
  11. setcookie('s1', $s1);
  12. setcookie('s2', $s2);
  13. setcookie('s3', $s3);
  14.  
  15. header("Location: next_page.php");
  16. exit;
  17. }
  18. ?>
  19.  
  20. <!DOCTYPE html>
  21. <html>
  22. <head>
  23. <title>Student Information</title>
  24. </head>
  25. <body>
  26. <h1>Student Information</h1>
  27. <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  28. <label for="n">Name:</label>
  29. <input type="text" name="n" id="n" required><br><br>
  30. <label for="s1">Subject 1:</label>
  31. <input type="number" name="s1" id="s1" required><br><br>
  32. <label for="s2">Subject 2:</label>
  33. <input type="number" name="s2" id="s2" required><br><br>
  34. <label for="s3">Subject 3:</label>
  35. <input type="number" name="s3" id="s3" required><br><br>
  36. <input type="submit" value="Submit">
  37. </form>
  38. </body>
  39. </html>
  40.  
  41.  
  42. next_page.php
  43.  
  44. <?php
  45. $cookies = ['n', 's1', 's2', 's3'];
  46. foreach ($cookies as $cookie) {
  47. if (isset($_COOKIE[$cookie])) {
  48. echo $_COOKIE[$cookie] . "<br>";
  49. }
  50. }
  51. ?>
  52.  
  53.  
  54. =====================================================================================
  55.  
  56.  
  57. 6.
  58.  
  59. <?php
  60. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  61. $input = $_POST['input'];
  62. $numbers = explode(',', $input);
  63. $sum = 0;
  64. $product = 1;
  65. $primeCount = 0;
  66. foreach ($numbers as $number) {
  67. $number = intval($number);
  68. if ($number % 2 === 0) {
  69. $sum += $number;
  70. }
  71. if ($number % 2 !== 0) {
  72. $product *= $number;
  73. }
  74. if (isPrime($number)) {
  75. $primeCount++;
  76. }
  77. }
  78. setcookie('sum', $sum);
  79. setcookie('product', $product);
  80. setcookie('primeCount', $primeCount);
  81. header('Location: p6.php');
  82. exit;
  83. }
  84. function isPrime($number) {
  85. if ($number < 2) {
  86. return false;
  87. }
  88. for ($i = 2; $i <= sqrt($number); $i++) {
  89. if ($number % $i === 0) {
  90. return false;
  91. }
  92. }
  93. return true;
  94. }
  95. ?>
  96. <!DOCTYPE html>
  97. <html>
  98. <head>
  99. <title>Variable Length Arguments</title>
  100. </head>
  101. <body>
  102. <h1>Variable Length Arguments</h1>
  103. <form method="POST" action="">
  104. <label for="input">Enter a comma separated string:</label>
  105. <input type="text" name="input" id="input" required>
  106. <button type="submit">Submit</button>
  107. </form>
  108. <?php
  109. if (isset($_COOKIE['sum']) && isset($_COOKIE['product']) && isset($_COOKIE['primeCount'])) {
  110. echo '<h2>Previous Results:</h2>';
  111. echo 'Sum: ' . $_COOKIE['sum'] . '<br>';
  112. echo 'Product: ' . $_COOKIE['product'] . '<br>';
  113. echo 'Prime Count: ' . $_COOKIE['primeCount'] . '<br>';
  114. }
  115. ?>
  116. </body>
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment