change background color with page refresh (lavalair)

Started on the old forum in April 2012 · view the original in the archive · old links redirect here

19 replies · 1,492 views · started 14 years ago · 1 min read

TL;DR · summary of 19 replies
  • - mirror was missing the closing PHP tag for his CSS code, so he needed to add ?> at the end of [code].
  • - The thread concluded with mirror still needing help implementing the CSS change on page refresh in core.php.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

7 participants
mirror Developer · 108 posts #1

friends any ideas how can i change background color of a page every time a page refreshes , but i want it for lavalair script

something else Fellow · 2,296 posts #2
session_start();
if(!isset($_SESSION['color'])) $_SESSION['color'] = 'red';
$color = $_SESSION['color'];
echo '<body bgcolor="'.$color.'">';
if($color=="red") $_SESSION['color'] = 'blue';
if($color=="blue") $_SESSION['color'] = 'yellow';
if($color=="yellow") $_SESSION['color'] = 'red';
//etc
mirror Developer · 108 posts #3

something else wrote:

session_start();
if(!isset($_SESSION['color'])) $_SESSION['color'] = 'red';
$color = $_SESSION['color'];
echo '<body bgcolor="'.$color.'">';
if($color=="red") $_SESSION['color'] = 'blue';
if($color=="blue") $_SESSION['color'] = 'yellow';
if($color=="yellow") $_SESSION['color'] = 'red';
//etc

can it b done using css

something else Fellow · 2,296 posts #4

change it to style.php

<?php
session_start(); 
if(!isset($_SESSION['color'])) $_SESSION['color'] = 'red'; 
$color = $_SESSION['color']; 
?>
body {background-color:<?=$color?>;}
<?
if($color=="red") $_SESSION['color'] = 'blue'; 
if($color=="blue") $_SESSION['color'] = 'yellow'; 
if($color=="yellow") $_SESSION['color'] = 'red';
?>
metulj Super moderator Principal · 1,726 posts #5

something else wrote: change it to style.php

<?php
session_start(); 
if(!isset($_SESSION['color'])) $_SESSION['color'] = 'red'; 
$color = $_SESSION['color']; 
?>
body {background-color:<?=$color?>;}
<?
if($color=="red") $_SESSION['color'] = 'blue'; 
if($color=="blue") $_SESSION['color'] = 'yellow'; 
if($color=="yellow") $_SESSION['color'] = 'red';
?>

if i'd use this, i'd use this way, as i hate short open tags LOL

<?php
session_start(); 
if(!isset($_SESSION['color'])) $_SESSION['color'] = 'red'; 
$color = $_SESSION['color']; 
?>
body {background-color:<?php echo $color; ?>;}
<?php
if($color=="red") $_SESSION['color'] = 'blue'; 
if($color=="blue") $_SESSION['color'] = 'yellow'; 
if($color=="yellow") $_SESSION['color'] = 'red';
?>

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

icedroplet1987 Senior · 258 posts #6

metulj wrote: i i'd use this, i'd use this way, as i hate short open tags LOL

<?php
session_start(); 
if(!isset($_SESSION['color'])) $_SESSION['color'] = 'red'; 
$color = $_SESSION['color']; 
?>
body {background-color:<?php echo $color; ?>;}
<?php
if($color=="red") $_SESSION['color'] = 'blue'; 
if($color=="blue") $_SESSION['color'] = 'yellow'; 
if($color=="yellow") $_SESSION['color'] = 'red';
?>

can you explain in brief (uses).

mirror Developer · 108 posts #7
* {
	margin: 0;
	padding: 0;
}
.alignleft {
float: left;
}
.alignright {
float: right;
}
.boxed {
	width: 99%;
	margin-bottom: 3px; 
	border: 1px solid #000000;
}
.boxedTitle {
	height: 18px;
	padding: 0 0 0 2px;
	background: ".$thm[1]." url(images/".$thm[2].") repeat-x;
}
.boxedTitleText {
	font-size: 11px;
	color: ".$thm[3].";
}
.boxedContent {
	padding: 2px 2px 2px 2px;
	background: ".$thm[4].";
	font-size: $fsize;
}
.logo {
	padding: 2px 2px 2px 2px;
	background: ".$thm[9]." url(images/".$thm[11].") repeat-x;
}
.footer {
	width: 100%;
	padding: 5px;
	background: url(images/".$thm[18].") repeat-x;
}
.gt {border-bottom: 1px solid #A9BF74; 0px 3px 3px;margin:0px 0px 8px; color: silver;}
h1 {
	color: #000000;
}
a:visited {
	color: ".$thm[6].";
}
a:link {
	color: ".$thm[5].";
}
h5 {
	height: 30px;
	padding: 0 0 0 2px;
	background: ".$thm[7]." url(images/".$thm[8].") repeat-x;
	color: ".$thm[3].";
}
body { 
background: ".$thm[9]." ;
font: normal small Arial, Helvetica, sans-serif, Verdana;
color: ".$thm[10].";
}
.inputText {
	background-color: ".$thm[12].";
	color: ".$thm[13].";
	border: 1px solid ".$thm[14].";
}
.inputButton {
	background-color: ".$thm[15].";
	color: ".$thm[16].";
	border: 1px solid ".$thm[17].";
}
</style>

thats my css in core.php , i want to change the background color of boxedContent on page refresh , m not able to use above given codes bro , when i tried it only used to show background color red , on refresh yellow , next on refresh i get blue , but in words it showed , colors didnt change

metulj Super moderator Principal · 1,726 posts #8

icedroplet1987 wrote: can you explain in brief (uses).

well.. as for typing purpose

<?=

is ofcourse shorter to type than

<?php echo

but... short open tag imho isnt really convenient... let's say you write a script with short tags, then you move the script to server which original settings is open_short_tag=off, and you dont have access to php.ini... BAD which is case on most shared hosts... but hey.. it could only my imagination..

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

something else Fellow · 2,296 posts #9

I Like php short tag being enabled..... you dont need php.ini can do it via .htacess:

php_value short_open_tag 1

also it reduces echo`s which slow your site down.... hence why ori wrote wapdesire v2 all with variables and one echo at the bottom of the page 🙂

arnage Lead · 811 posts #10

something else wrote: I Like php short tag being enabled..... you dont need php.ini can do it via .htacess:

php_value short_open_tag 1

also it reduces echo`s which slow your site down.... hence why ori wrote wapdesire v2 all with variables and one echo at the bottom of the page :)

Only if your coding style is mixing markup and php, which is not quite efficiently. PHP turns on, php turns off, turns on, turns off, on, off, on off on off... 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Ghost Senior · 366 posts #11

something else wrote: I Like php short tag being enabled..... you dont need php.ini can do it via .htacess:

php_value short_open_tag 1

also it reduces echo`s which slow your site down.... hence why ori wrote wapdesire v2 all with variables and one echo at the bottom of the page :)

interesting and good advice at same time, although i have to say i do prefer full tags, it just looks cleaner and makes it look like you wanted to go that extra mile lol 😉

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
something else Fellow · 2,296 posts #12

lol i think the opposite .... i think it looks cleaner without millions of echo`s and also looks like you know a little more about server config etc but its personal choice i guess 🙂

something else Fellow · 2,296 posts #14

lol if you have got such a large .css of 400 lines then it would be far better off doing it on a variables anyway rather than 400 echo`s or <?=

subzero Super moderator Fellow · 3,954 posts #15

I love php

 function include_emulating_short_tags ($viewFile)
  {
    // Alternate method for making <?= valid
    $raw = file_get_contents ($viewFile);
    $raw = str_replace ('<?=', '<?php echo ', $raw); 
 
    $html = '';
    $phptokens = @token_get_all ($raw);
 
    $mode    = 'text';
    $phpcode = '';
    foreach ($phptokens as $ptoken)
    {
      if (($mode == 'text') && is_array ($ptoken) && ($ptoken[0] === T_OPEN_TAG)) {
        $mode = 'php';
        continue;
      }
 
      if (($mode == 'php') && is_array ($ptoken) && ($ptoken[0] === T_CLOSE_TAG)) {
        ob_start();
        eval ($phpcode . ';');
        $html .= ob_get_contents();
        ob_end_clean();
 
        $mode    = 'text';
        $phpcode = '';
        continue;
      }
 
      if ($mode == 'text') { 
        $html .= is_array ($ptoken) ? $ptoken[1] : $ptoken;
      }
      else {
        $phpcode .= is_array ($ptoken) ? $ptoken[1] : $ptoken;
      }
    }
 
    if (($mode == 'php') && ($phpcode !== '')) {
      ob_start();
      eval ($phpcode);
      $html .= ob_get_contents();
      ob_end_clean();
    }
 
    return $html;
  }
<?php=shif();?> or <?php echo shif(); ?> or plain <?php shif(); ?>

Tells PHP whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"?>'; ?>. Also, if disabled, you must use the long form of the PHP open tag (<?php ?>).

Note:

This directive also affected the shorthand <?= before PHP 5.4.0, which is identical to <? echo. Use of this shortcut required short_open_tag to be on. Since PHP 5.4.0, <?= is always available.

PHP: Description of core php.ini directives - Manual

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

mirror Developer · 108 posts #16

lol whats going on here arent we going off topic , need help with tht css friends to make it work

something else Fellow · 2,296 posts #17

you should be able to work it out mirror .... its not hard 😉

arnage Lead · 811 posts #18

something else wrote: lol if you have got such a large .css of 400 lines then it would be far better off doing it on a variables anyway rather than 400 echo`s or <?=

Well thats about for both, defining by user, retrieving from form, checking or setting defaults and writing onto database, and for reading from it and again checking and display it. All with ternary and loops, and thats how its gonna work, i will finalize it at the end of writing the script and design it, now its all in separate files out of the script. 🙂

mirror wrote: lol whats going on here arent we going off topic , need help with tht css friends to make it work

No, and only if you are waiting for someone to write it for you, now you should try to write it and if it doesn't go good post here what you have tried. All what it need is shuffle() or some kind of random. 😉

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
mirror Developer · 108 posts #19

okay arnage bro help me out here , i tried this

in core.php what next its still not working

$background_colors = array('#282E33', '#25373A', '#164852', '#495E67', '#FF3838');

$count = count($background_colors) - 1;

$i = rand(0, $count);

$rand_background = $background_colors[$i];

$blah = "<style type=\"text/css\">
* {
	margin: 0;
	padding: 0;
}
.alignleft {
float: left;
}
.alignright {
float: right;
}
.boxed {
	width: 99%;
	margin-bottom: 3px; 
	border: 1px solid #000000;
}
.boxedTitle {
-webkit-border-radius: 10px;
	-khtml-border-radius: 10px;	
	-moz-border-radius: 10px;
	border-radius: 10px;
	height: 18px;
	padding: 0 0 0 2px;
	background: ".$thm[1]." url(images/".$thm[2].") repeat-x;
}
.boxedTitleText {
	font-size: 11px;
	color: ".$thm[3].";
}
.boxedContent {
	padding: 2px 2px 2px 2px;
	background: <?php echo $rand_background; ?>;
	font-size: $fsize;
}

WHAT M I MISSING HERE

arnage Lead · 811 posts #20

Line

background: <?php echo $rand_background; ?>;

write like

background: $rand_background;

Because all that is in $blah = " ... already and it should display.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close