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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.