PHP Changing text colour of $_SESSION

I am creating a login script for a webpage. The code validates the data inputted and if there is something wrong, it posts text to the web page. However, this text is in black and can't be seen on a black website. I've tried setting a div around my code, css body styling but none of it works.

Here is an example line from my code

if($_POST['password'] == '')  {
$_SESSION['error']['password'] = "Password is required.";  

In this case, the "Password is required" will be in black text but I would like it in white. If it helps, towards the end of my code I have:

  header("Location: index.php");

Any ideas would be much appreciated



$_SESSION['error']['password'] = "<span style='color:#FFFFFF'>Password is required.</span>";

Do it with css in your file where you are showing error. Say you are showing error in index.php like

  <div id="errors"><?php echo $_SESSION['error']['password'];?></div>

Add the following CSS somewhere better in head in index.php

 #errors {
   color: #FFFFF;

Give a color which you want for the error container like

<div style='color:#FF0000'> <?php echo  $_SESSION['error']['password']; ?> </div>

In your index.php file you have to echo some html with appropriate css. For example you should have line similar to below one:

echo '<p style="color:#FF0000">Password is required.</p>';

Above html will result in paragraph with red text.

tag can be replaced by , , or any other suitable tag which is allowed to contain text inside.

However, this text is in black and can't be seen on a black website

You have deducted correctly as to why you can't see your text. If you look at your code, you can see that once your $_SESSION super global is set, it will redirect to index.php.

Inside your index.php, you are rendering that text as black and your background as black. Please wrap your errors in a div tag:

<div class="errors"><?=$_SESSION['error']['password'];?></div>

By best practice, you should link a CSS style page at the top of your index page:

 <link rel="stylesheet" href="style.css">

Within your CSS, you can then define a styling for your error:

.errors { color: white;}

Remember, a header is a redirect and thus the page it redirects to will be the properties that will be returned upon response of your request. Keeping this in mind will allow you to properly style your page by showing errors that may populate during your session life.

Need Your Help

How can I ensure that an iframe inherits the browser mode and document mode of its parent?

javascript iframe dojo doctype

I have a Web page whose purpose is to be embedded in various other pages via an iframe. Those pages have different doctypes and are used on different browsers.

CSS1 Sprite animation on mouse hover?

css animation hover mouse sprite

I know if I hover my mouse over a CSS1 Sprite it will switch to the hover image, but is there a way to get it to load more images sequentially on mouse hover, like an animation? Please, no CSS3

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.