0

I Have stored the session value like this on header.php

$order_total = $_SESSION['order_total'];

And I get a warning message every time I login

Notice: Undefined index: order_total in C:\xampp\htdocs\zzz\frontend\header.php on line 15

And once I go to that page again, the message was removed

Goma
  • 2,018
  • 1
  • 10
  • 19
naveen
  • 41
  • 6
  • Please check session is set or not if it is set then store in $order_total varriable else set null value in it,or provide me you code – Arshad Shaikh Dec 19 '17 at 05:00
  • Have you started the session in every file on the first line with `start_session()`? – Geshode Dec 19 '17 at 05:05
  • Make sure you have started session using session_start(); before using session make sure you have set $_SESSION['order_total'] before accessing it . If it doesn't work try turning on output buffering using ob_start() in the beginning – Deepak Kumar T P Dec 19 '17 at 05:07
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – urfusion Dec 19 '17 at 05:30

1 Answers1

0

You have to check session first

session_start();

if(isset($_SESSION['order_total']) && !empty($_SESSION['order_total'])) {
   $order_total = $_SESSION['order_total'];
}else{
   $order_total = "session is not set";
}
TarangP
  • 2,711
  • 5
  • 20
  • 41