Ok I have a session started within my application and it gets a session variable that defines a theme.
I have this code, but it doesn't seem to be working at all. Basically I want this to select the correct stylesheet based on the theme the user chose at registration. So if they selected the Default theme I would need the default css file to be linked and so on...
I am fairly new to PHP so if it's completely wrong, tell me but please help and tell me what's wrong. We all start somewhere.
<?php
$themeName = '$_SESSION["SESS_THEME_NAME"]';
if ($themeName == "Default") {
echo '<link rel="stylesheet" type="text/css" href="mws-theme.css" />';
}
if ($themeName == "Army") {
echo '<link rel="stylesheet" type="text/css" href="mws-theme-army.css" />';
}
if ($themeName == "Rocky Mountains") {
echo '<link rel="stylesheet" type="text/css" href="mws-theme-rocky.css" />';
}
if ($themeName == "Chinese Temple") {
echo '<link rel="stylesheet" type="text/css" href="mws-theme-chinese.css" />';
}
if ($themeName == "Boutique") {
echo '<link rel="stylesheet" type="text/css" href="mws-theme-boutique.css" />';
}
if ($themeName == "Toxic") {
echo '<link rel="stylesheet" type="text/css" href="mws-theme-toxic.css" />';
}
if ($themeName == "Aquamarine") {
echo '<link rel="stylesheet" type="text/css" href="mws-theme-aquamarine.css" />';
}
?>
Remove the single quotes.. http://php.net/manual/en/language.variables.php
$themeName = $_SESSION["SESS_THEME_NAME"];
If that doesn't work, make sure that you have started the session http://php.net/manual/en/function.session-start.php
session_start()
make sure you start session on this page and edit the following,
$themeName = $_SESSION["SESS_THEME_NAME"];
Related
i am using transposh to translate my website from English to Arabic but when i switch language to Arabic it switches the style.css and it reverse the layout of my website leading to a mess, so i made a new style.css which works with the Arabic version very well but now i don't know how to link them together i mean i want to know how to make it switch the css file when it switches the language.
i tried this code but it didn't work
<?php if(MY_CUR_LANG == 'en'){?>
<link rel="stylesheet" href="http://localhost/wordpress/wp-content/themes/style.css" type="text/css" media="screen" />
<?php }elseif(MY_CUR_LANG == 'ar'){?>
<link rel="stylesheet" href="http://localhost/wordpress/wp-content/themes/arabic.css" type="text/css" media="screen" />
<?php } ?>
You cannot jump in and out php code. Try
<?php
if(MY_CUR_LANG == 'en'){
echo'<link rel="stylesheet" href="http://localhost/wordpress/wp-content/themes/style.css" type="text/css" media="screen" />';
}elseif(MY_CUR_LANG == 'ar'){
echo'<link rel="stylesheet" href="http://localhost/wordpress/wp-content/themes/arabic.css" type="text/css" media="screen" />';
}
?>
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 8 years ago.
The code below is the main index page of my website. It's working perfectly fine on my test server--redirecting me to the login page if I'm not logged in, or if any session is not set. However, I uploaded it to my live server--it's working fine there as well, until I change the url from index.php?X=0&Y=0 to index.php. At which point it only shows a the background and nothing else.
Everything was working fine on both ends until earlier today when I reuploaded everything to my server, but none of the code has changed so nothing should be different, but it is. So, I wondering if you guys see anything that could be causing it.
There are no errors, the page just doesn't load properly.
<?php //* Something Wicked This Way Comes *//
require_once("lib/bootstrap.php");
$html = '<!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">'.
'<head>'.
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.
'<meta name="description" content="Control the Universe!"/>'.
'<meta name="keywords" content="game,web based, reddact, arg, story, gmz1023,elements" />'.
'<title>Reddact</title>'.
'<link rel="stylesheet" href="assets/style.css" />'.
'<link rel="stylesheet" type="text/css" href="assets/css/tooltipster.css" />'.
'<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>'.
'<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>'.
'<script src="js/jquery.tooltipster.min.js" type="text/javascript"></script>'.
'<script src="js/TimeCircles.js" type="text/javascript"></script>'.
'<script src="js/jquery.validate.min.js"></script>'.
'<script src="js/js.js" type="text/javascript"></script>'.
'<link href="favicon.ico" rel="icon" type="image/x-icon" />'.
'<link rel="stylesheet" href="js/TimeCircles.css" />'.
'</head>'.
'<body>';
echo $html;
if(!isset($_SESSION))
{
include('parts/login-page.php');
}
if(!isset($_SESSION['uid']))
{
if(!isset($_GET['error']))
{
include('parts/login-page.php');
}
else
{
include('parts/login-page.php');
}
}
if(isset($_SESSION['uid']))
{
if(isset($_GET['mode']))
{
$file = 'parts/active/'.$_GET['mode'].'.php';
if(file_exists($file))
{
include($file);
}
else
{
include('404.html');
}
}
else
{
if(!isset($_GET['X']) && !isset($_GET['Y']))
{
header('Location:'.$_SESSION['index']);
}
else
{
if(isset($_GET['portal']))
{
include('first_time.php');
}
else
{
include('starmap.php');
include('nav-menu.php');
}
}
?>
</div>
</body>
</html>
<?php
}
}
?>
This block:
if(!isset($_GET['X']) && !isset($_GET['Y']))
{
header('Location:'.$_SESSION['index']);
}
is the problem. You cannot change the header after outputting anything. It will often not be caught on localhost, but will most certainly not work on a live server.
Try putting echo $html; somewhere below the series of if-else statements.
<?php
html = '<!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">'.
'<head>'.
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.
'<meta name="description" content="Control the Universe!"/>'.
'<meta name="keywords" content="game,web based, reddact, arg, story, gmz1023,elements" />'.
'<title>Reddact</title>'.
'<link rel="stylesheet" href="assets/style.css" />'.
'<link rel="stylesheet" type="text/css" href="assets/css/tooltipster.css" />'.
'<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>'.
'<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>'.
'<script src="js/jquery.tooltipster.min.js" type="text/javascript"></script>'.
'<script src="js/TimeCircles.js" type="text/javascript"></script>'.
'<script src="js/jquery.validate.min.js"></script>'.
'<script src="js/js.js" type="text/javascript"></script>'.
'<link href="favicon.ico" rel="icon" type="image/x-icon" />'.
'<link rel="stylesheet" href="js/TimeCircles.css" />'.
'</head>'.
'<body>';
echo $html;
and then after some code you say:
header('Location:'.$_SESSION['index']);
answer is: Headers already sent error
Headers must be set BEFORE any html content is shown
so first: header
then echo the html
also check if your index.php?X=0&Y=0 works if not (I assume here is the redirect) if so it's logically your php.ini doesn't show errors because display_errors is probably on 0
also like I said above here first sending the headers (html) and after that modify the header (header()) is not allowed.
so what you want to do is putting that whole redirect if statement above the echo $html; and you should be fine...
I have a index.php file which loads (require) 2 different files based on a condition.
Visiting this link will cause;
mysite.com/index.php will load stats.php (require("stats.php");)
Visiting this link will cause;
mysite.com/index.php?auth="jgbsbsbasm" will load encry.php (require("stats_encry.php");)
Done with this code:
<?php
if(isset($_GET['auth'])) require("stats.php");
else require("stats_encry.php");
?>
This works fine. Now my question is; I have a CSS file in the header as static;
<link rel="stylesheet" href="cv.css">
What I want is now to load cv.css file for stats.php and cv1.css for stats_encry.php respectively.
How do I do this?
In your header replace
<link rel="stylesheet" href="cv.css">
with
<?php if(isset($_GET['auth'])){ ?>
<link rel="stylesheet" href="cv.css">
<?php } else { ?>
<link rel="stylesheet" href="cv1.css">
<?php } ?>
You can use this like below syntax
<?php
if(isset($_GET['auth'])){
echo '<link rel="stylesheet" href="cv.css">';
} else {
echo '<link rel="stylesheet" href="cv1.css">';
}
?>
My idea is to switch multiple links to CSS files, if special URL was detected. But I have a trouble: my code includes only css in the first if..else statement. And it doesn't depend on the URL.
Here is my code.
http://pastebin.com/Jm3QFDmH
ported from pastebin
<?php
// get first folder in URL
$f_folder = substr(substr($_SERVER["REQUEST_URI"],1), 0, strpos(substr($_SERVER["REQUEST_URI"],1), "/"));
//get full directory structure from URL for current page
$full_path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
//css for account
if ($f_folder='account') {
?>
<link rel="stylesheet" href="/mainstyle/common.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/mainstyle/account.css" type="text/css" charset="utf-8" />
<?php
} elseif ($f_folder='signin'||$f_folder='signup'||$full_path='/account/resetPassword'||$full_path='/account/logout') {
?>
<link rel="stylesheet" href="/mainstyle/login-signup.css" type="text/css" charset="utf-8" />
<?php
} else {
?>
<link rel="stylesheet" href="/mainstyle/common.css" type="text/css" charset="utf-8" />
<?php
}
?>
Where is mistake?
if and elseif, should have == comparison operator , not = assignment
Line 7 should be
if ($f_folder=='account') {
I am using multiple stylesheets and need the pages to differ based on category.
I added the following to my header.php, but shows base theme`s single entry template. Any ideas?
<?php if (is_category('20')) { ?>
<link rel="stylesheet" type="text/css" href="wp-content/themes/tanzaku/style.css" />
<?php } else {?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/style.css" />
<?php } ?>
I am using the same theme as these sites, but I use two themes on my site compared to these.
http://marioortega.net/
http://atelier6.co.uk/
When you click one of the thumbnails, the single ends up on top and the thumbnails at the bottom.
All:
Thank you for looking into this. In order for me to get this to work, the problem was actually multiple single.php files. This can be solved by having your single.php look like this,
<?php
$post = $wp_query->post;
if ( in_category('20') ) {
include(TEMPLATEPATH . '/single1.php');
} else {
include(TEMPLATEPATH . '/single2.php');
}
?>
I have also edited the question for other people looking for this answer.
Shouldn't you be using echo statement to put the link into your page.
<?php
if (is_category('20')) {
echo '<link rel="stylesheet" type="text/css" href="wp-content/themes/tanzaku/style.css" />';
}
else {
echo '<link rel="stylesheet" type="text/css" href="'.bloginfo('template_url').'/style.css" />';
}
?>