PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 15, 2022

[FIXED] how can i fix undefined varriable in laravel?

 November 15, 2022     cookies, css, laravel, laravel-6, session     No comments   

Issue

i wrote a code in my blade page in LARAVEL that can change them dynamically by user .

i save css styles in cookie and i defined css variable in my codes

but in main page i get this error : Undefined index: css

my code :

 <?php
session_start();

$default = 'dark.css'; // define stylesheets
$darkcss = 'dark.css';
$lightcss = 'light.css';

$expire = time()+60*60*24*30; // how long to remember css choice (60*60*24*30 = 30 days)

if ( (isset($_GET['css'])) && ($_GET['css'] == $lightcss) ) { // set cookie for light css
    $_SESSION['css'] = $_GET['css'];
    setcookie('css', $_GET['css'], $expire);
}

if ( (isset($_GET['css'])) && ($_GET['css'] == $darkcss) ) { // set cookie for dark css
    $_SESSION['css'] = $_GET['css'];
    setcookie('css', $_GET['css'], $expire);
}

if ( (isset($_GET['css'])) && ($_GET['css'] == $default) ) { // set cookie for default css
    $_SESSION['css'] = $_GET['css'];
    setcookie('css', $_GET['css'], $expire);
}

if (isset($_COOKIE['css'])) { // check for css stored in cookie
    $savedcss = $_COOKIE['css'];
} else {
    $savedcss = $default;
}

if ($_SESSION['css']) { // use session css else use cookie css
    $css = $_SESSION['css'];
} else {
    $css = $savedcss;
}

// the filename of the stylesheet is now stored in $css
echo '<link href="/admin/assets/css/'.$css.'" rel="stylesheet" type="text/css" />'
?>

Solution

problem is here

if ($_SESSION['css']) { // use session css else use cookie css

in this line u miss isset() that's why u r getting error



Answered By - Kamlesh Paul
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing