simple CSS switcher and save cookie - html

I want to create a button that can switch between stylesheets (example below) and I would like for it to create a cookie so that the browser remembers and saves the setting.
<button id="style1">Light</button>
<button id="style2">Dark</button>
<link rel="stylesheet" type="text/css" href="style1.css">
<link rel="stylesheet" type="text/css" href="style1.css">
The simpler the code the better. Thank you!

You can use PHP to set and get the cookie and change the style based on that.
switch1.php
<?php
setcookie("s", "1");
header("Location: index.html");
?>
switch2.php
<?php
setcookie("s", "2");
header("Location: index.html");
?>
index.html
<link rel="stylesheet" type="text/css" href=
<?php
if isset($_COOKIE["s"]))
echo '"style' . $_COOKIE["s"] . '.css"';
else
echo '"style1.css"';
?>
>
<button id="style1">Light</button>
<button id="style2">Dark</button>

Related

How to disable CSS on a specific page?

I am using 3 stylesheets (style1, style2, style3) for many pages.
style1 for my web header,
style2 for my contents and
style3 for footer
Now I want to apply a new stylesheet on my home page and disable style2 for only home page.
I added new classes for different elements but at some places it is still detecting my previous stylesheets. How can I disable CSS on a specific page?
Since you did not include the code to see how you doing it, and considering you are having the header as an include file:
USE PHP:
In your Home page before including header:
<?php $homepage = 1; ?>
//include your header//
In your header where you are referencing CSS:
<link href="css/style1.css" rel="stylesheet" type="text/css" />
<link href="css/style3.css" rel="stylesheet" type="text/css" />
<link href="<?php if($homepage == 1){ echo "css/Home-style.css";}else{ echo "css/style2.css";}?>" rel="stylesheet" type="text/css" />
Your files should be in PHP for this to work.
change "Home-style.css" to your new CSS file for home page.
Check for page then grab the dom stylesheets array object and disable anything you want .
if(window.location.href.indexOf("<name in page url >") > -1) {
//Next line will disable the 2nd stylsheet in the document .
document.styleSheets[1].disabled = true;
}
Also fyi you can view all style sheets in the dom with:
console.log(document.styleSheets)
This should give you the appropriate index of whatever stylesheet you want to remove.
You have to use jQuery to disable a stylesheet like :
<script>
$(function () {
if (location.pathname.indexOf('/pagename') >= 0) {
$('link[href*="/media/css/csspagename.css"]').prop('disable', true);
}
});
</script>

Showing different links depending on who is logged in

I'm trying to create a few links that change depending on who is logged in, for example when a user logs in, log in changes to log out, just started making the if statements but they dont seem to recognise the sessions. Can anyone see an issue? Excuse the poor layout, been playing around.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<?php
session_start();
?>
<link rel="stylesheet" type="text/css" href="skeleton.css" />
<link rel="stylesheet" type="text/css" href="normalize.css" />
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Assignment1</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
</head>
<body>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<?php
if (isset($_SESSION['userlogged']))
{
?>
<div class="container">
<div class="row">
<center><h4>Basic Requirements</h4>
<pre>
Logout Registration Contact Search
</pre>
</div>
</center>
</div>
<?php
}
else if (isset($_SESSION['adminlogged']))
{
}
else
{
?>
<div class="container">
<div class="row">
<center><h4>Basic Requirements</h4>
<pre>
Logout Registration Contact Search
</pre>
</div>
</center>
</div>
<?php
}
?>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>
Loginsubmit.php
<?php
session_start();
?>
<font face="ClearSans-Thin">
<font color="lightgray">
<?php
include 'connection.php';
include 'loginform.php';
?>
<center>
<?php
if (isset($_POST['submit']))
{
$user = $_POST['username'];
$pass = $_POST['password'];
//Counts up how many matches there are in the database
$query = "SELECT COUNT(*) AS cnt FROM users WHERE Username ='" . mysqli_real_escape_string($connection, $user) . "'AND Password='" . mysqli_real_escape_string($connection, $pass). "'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
/*$queryadmin = "SELECT COUNT(*) AS cnt FROM admin WHERE Username ='" . mysqli_real_escape_string($connection, $user) . "'AND Password='" . mysqli_real_escape_string($connection, $pass). "'";*/
/*$resultadmin = mysqli_query($connection, $queryadmin);*/
/*$rowadmin = mysqli_fetch_assoc($resultadmin);*/
//If count is more than 0, log user in.
if ($row["cnt"] > 0)
{
$_SESSION["userlogged"] = $user;
echo "Logged in - Press the home button to return to the homepage";
}
else if ($rowadmin["cnt"] > 0 )
{
$_SESSION["adminlogged"] = $user;
echo "Logged in - Press the home button to return to the homepage";
}
else
{
echo 'Not a valid login';
}
}
?>
your index page needs the session_start(); to read session variables
session_start();
echo $_SESSION['userlogged'];

No video with supported format and mime type in my php code

alert('Your Comment is added!')";
}
else{
echo "alert('Cannot Comment')";
}
}
?>
<!doctype html>
<meta charset="UTF-8">
<meta name="description" content="" >
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compaign Shack </title>
<link rel="shortcut icon" type="image/png" href="img/fevicon.png"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1
/jquery.min.js">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4
/js/bootstrap.min.js">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<![endif]-->
<style>
#comment{
border-bottom-left-radius:5px;
border-bottom-right-radius:5px;
border-top-left-radius:5px;
border-top-right-radius:5px;
box-shadow: 10px 10px 5px #888888;
}
<div class="container">
Advetising Agency :
".$agency." , Brand Name : ".$row['br_name'].""; ?>
Television
Image
Outdoor
Print
Digital
radio";
?>
'>
" type="video/mp4">
" type="video/ogg">
" type="video/webm">
"
style='width:60%; height:60%'>
"
style='width:60%; height:60%'>
"
style='width:60%; height:60%'>
" style='width:60%;
height:60%'>
"
style='width:60%; height:60%'>
</div>
Other Details
Other Details :
"; ?>
Creative Team : $cr
";
echo "Month : $row[month]
";
echo "Advertising Agency :
$row[ad_agency]";
echo "Account Team : $a_t ";
echo "Brand Name : ".$b_name."
Campaign Slogan : ".$c_slo ."
Media Release : ".$m_r ."
Account Leader : " . $a_l ."
Production : ". $pr ."
Research Agency : ". $r_a ."
Additional Credit : ". $a_c."
Media : TV,Radio,Outdoor,Digital,Print
";
}
?>
2014-03-06 7:37 am
hallo, please help me, i get invalid
article id, i already follow all the instruction and no such
php?id=1 at my page, im using phpadmin v 5.1,
without article id, nothing i can progress. tq
-->
Wanna Comment ?? Login here";
}
else{
echo "
";
}
?>
";
echo ''.$rrrr[3].'';
echo "
2014-03-06 7:37 am";
echo "".$rrrr[2]."
";
$na=$rrrr[3];
if($na==$una){
echo "";
}
echo "
";
}
/*
echo "";
$qqq="select * from comment where post_id=".$_GET['id'];
$rrr=mysqli_query($con,$qqq);
while($rrrr=mysqli_fetch_array($rrr))
{
$na=$rrrr[3];
echo "
$rrrr[3]
$rrrr[2]
";
if($una==$na){
echo " delete
";}
else{
echo "";
}
echo "
";
}
?>
*/
?>
| Login
| Register
Campaign Shack News
Have you ever stumbled across a Pakistani advertisement and
wondered about the people and agencies behind the advertising campaign? The
creative minds who have attempted to communicate some brand related message to
you?
Or about the ad work that was done in a
particular time frame?
Have you ever stumbled across a Pakistani advertisement and wondered
about the people and agencies behind the advertising campaign? The creative
minds who have attempted to communicate some brand related message to you?
Or about the ad work that was done in a
particular time frame?
Space for Google Adds
</div>
<?php include("footer.php"); ?>
<div id="picture_view" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×
<h4 class="modal-title">View</h4>
</div>
<div class="modal-body">
<img src='img/1.png '/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">Close
</div>
</div>
</div>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/custom.js"></script>
When i upload a video individually from FTP it will play and when i'll upload form a website it show the mime type or something remove type error
Here is the Link:
http://campaignshack.com/subarchives.php?id=85
Firstly, you see the semi-colon in
$row=mysqli_fetch_array($res);{
^ right there
that is killing your script and tells it to end the statement.
Nothing in there will executed.
Remove it.
$row=mysqli_fetch_array($res){
However, that should be a while loop.
while($row=mysqli_fetch_array($res)){...}
as in:
while($row=mysqli_fetch_array($res)){
$img1=$row['image'];
$video=$row['video'];
$show="/vdo/".$video;
$lom=$row['lo_med'];
$agency=$row['ad_agency'];
}
Also make sure that $_GET['id'] is indeed an int and not a string.
Add or die(mysqli_error($con)) to mysqli_query().
If it is a string, then you will need to modify your query, such as:
$id = $_GET['id'];
$query="select * from archives where id='".$id."'";
But this method is open SQL injection, use mysqli with prepared statements, or PDO with prepared statements, they're much safer.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.

Strange Joomla element placing error (css error?)

On this site: http://www.gruene-chemnitz.de/abgeordnete the right sidebar gets placed below the main content. Which of course isn't supposed to happen.
But this is the only page where this happens on the entire site. I'm not able to find the difference or get a clue whats wrong.
I would really appreciate your help in fixing the error.
Edit: The index.php of the used template looks like this:
<?php defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
<link rel="shortcut icon" href="templates/<?php echo $this->template ?>/images/favicon.ico" />
<?php if($this->countModules('left and right') == 0) $contentwidth = "100";
if($this->countModules('left or right') == 1) $contentwidth = "80";
if($this->countModules('left') != 0) $contentwidth = "81";
if($this->countModules('left and right') == 1) $contentwidth = "60";
?>
</head>
<body>
<div id="page-outer">
<div id="top"><jdoc:include type="modules" name="top" style="xhtml"/></div>
</div>
<div id="page">
<div id="header"></div>
<div id="shadow"><div class="shadow"><jdoc:include type="module" name="breadcrumbs"/></div></div>
<div class="inside">
<div id="sidebar">
<div class="insideleft"><jdoc:include type="modules" name="left" style="xhtml"/></div>
</div>
<div id="content<?php echo $contentwidth;?>"><jdoc:include type="component" />
<div id="footer">©Bündnis 90 die Grünen <?php echo date("Y",time());?></div>
</div>
<div id="sidebar-2">
<div class="insideleft"><jdoc:include type="modules" name="right" style="xhtml"/></div>
</div>
</div>
</div>
</body>
</html>
check below div control position on your page html source
content60 and
sidebar-2
i think there is a html break on module with div content60. so check html first.
hope this will help you.
thanks
First you have tables based layout. Second your div#sidebar-2 is inside the div#content60. Remove the div#sidebar-2 ouside the div#content60 in your HTML markup.
Like for example here gruene-chemnitz.de, the div#sidebar-2 is outside the div#content60 and these two along with div#sidebar are the children of div.inside
Almost all occurences of templates blowing apart on specific pages can be traced down to invalid html within an article - or module.
Within your content it looks like you have closed a div that wasn't open - this is then interpreted by the browser as an earlier div as well as closing some intermediate td tags and other things - basically blowing your template apart.
The easiest fix would be to view the source within your article - within the wysiwyg editor and count how many times you open divs versus how many you close.
To give you an idea of where to look use the html validator:
http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fwww.gruene-chemnitz.de%2Fabgeordnete

Switching to Codeigniter HMVC - Undefined functions?

I have setup a fresh install of codeigniter 2x and modular extensions (https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home)
It is my first time using HMVC, the decision to move from MVC to HMVC was to give myself more control of my login, admin, and members areas.
I have created my first controller in HMVC like so....
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends MX_Controller {
function __construct()
{
parent::__construct();
$this->load->model('Content_model');
}
public function index()
{
$this->load->view('includes/template');
}
}
and a view like:
<?php echo doctype(); ?>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $pagecontent['seo_title']; ?></title>
<meta name="description" content="<?php echo $pagecontent['seo_description']; ?>" />
<meta name="keywords" content="<?php echo $pagecontent['seo_keywords']; ?>" />
<meta name='robots' content='all' />
<link rel="icon" type="image/ico" href="<?php echo base_url("images/favicon.png"); ?>" />
<?php echo link_tag('css/style.css'); ?>
<script type="text/javascript" language="javascipt" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="<?php echo base_url("js/jquery.validate.min.js"); ?>"></script>
<script type="text/javascript" language="javascript" src="<?php echo base_url("js/main.js"); ?>"></script>
</head>
<body>
<?php $this->load->view('includes/notify'); ?>
<div id="topbar">
<?php $this->load->view('includes/topbar'); ?>
When I try and view the page in my browser I get the following error:
Fatal error: Call to undefined function doctype() in C:\xampp\htdocs\mintfifty\application\modules\site\views\includes\template.php on line 1
The code has worked in all my previous codeigniter (mvc) projects but not (hmvc) why is it not working in HMVC? What am I doing wrong?
This issue is not likely to be caused by HMVC. doctype() function is defined in html helper and it seems that You have not loaded it (Unless you have auto-loaded it). Just load the html helper in your controller and it should work fine.
public function index()
{
$this->load->helper('html');
$this->load->view('includes/template');
}