LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-29-2004, 09:31 AM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
PHP code did not create a cookie and it did not changed the background and text color


Initially, the code load the page, and default the background and text color to white. I then select a different background and text color, and I clicked the submit button. The page refreshes but the background and text color was not changed, and it never created a cookie on my PC.

On IE 6.0, I set the cookies option to prompt
I selected Tools --> Internet Options --> Privacy -->
Advanced --> set the First-Party Cookies to prompt

=================================
Code:
<?PHP

if ($BeenSubmitted)
 {
   setcookie("BGColor", "$NewBGColor");
   setcookie("TextColor", "$NewTextColor");
   $BGColor = $NewBGColor;
   $TextColor = $NewTextColor;
 }
else
 {
   if (!$BGColor)
     $BGColor = "WHITE";

   if (!$TextColor)
     $TextColor = "BLACK";
 }
?>

<HEAD>
<TITLE>User Customization</TITLE>
</HEAD>


<?
  print ("<BODY BGCOLOR=$BGColor TEXT=$TextColor>\n");
?>


Currently your page looks like this!
<FORM ACTION="linh_cookies.php" METHOD=POST>

Select a new background color:
<SELECT NAME="NewBGColor">
  <OPTION VALUE=WHITE>WHITE</OPTION>
  <OPTION VALUE=BLACK>BLACK</OPTION>
  <OPTION VALUE=BLUE> BLUE </OPTION>
  <OPTION VALUE=RED>  RED  </OPTION>
  <OPTION VALUE=GREEN>GREEN</OPTION>
</SELECT>

Select a new text color:
<SELECT NAME="NewTextColor">
  <OPTION VALUE=WHITE> WHITE</OPTION>
  <OPTION VALUE=BLACK> BLACK</OPTION>
  <OPTION VALUE=BLUE>  BLUE </OPTION>
  <OPTION VALUE=RED>   RED  </OPTION>
  <OPTION VALUE=GREEN> GREEN</OPTION>
</SELECT>

<INPUT TYPE=HIDDEN NAME=BeenSubmitted VALUE=TRUE>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">

</FORM>
</BODY>
</HTML>
 
Old 07-29-2004, 10:22 AM   #2
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Use the global arrays to check for values instead.

These are $_POST, $_GET, $_REQUEST, $_SESSION, etc.

For example, to get the value from a post form use $_POST['NewBGColor']. ($_GET for get forms or just use $_REQUEST which checks them all).

Code:
if(isset($_POST['BeenSubmitted'])) {
   ...
   $BGColor = $_POST['NewBGColor'];
}
 
Old 07-29-2004, 11:33 AM   #3
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
Yep the above code is correct , well its'
the new feature they have added in php4 and above
you better check out the version of php you are using
and check out its' documentation.
 
Old 07-29-2004, 11:37 AM   #4
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Yeah, i should've mentioned that the original code is "correct", but some configurations (and new versions) of php don't automatically set the variables ($NewBGColor from $_POST['NewBGColor']) so it's best to use the new method instead.
 
Old 07-29-2004, 12:23 PM   #5
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
Smile reply

Thank you everyone for your help.

The function setcookie("TextColor", "$NewTextColor"); did not put a cookie into my PC.


Is the statement with $_POST is from version 3 or version 4 ?
$BGColor = $_POST['NewBGColor'];

Last edited by Linh; 07-29-2004 at 12:45 PM.
 
Old 07-29-2004, 10:15 PM   #6
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
i think its' from version 4
thats' what i know
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VI Background Text Color mahugl Linux - Newbie 3 12-15-2013 10:12 PM
How change text color using linux in text mode only runlevel 3? Xavius Linux - General 7 05-07-2009 02:19 AM
Using [code] inside of [color] results in very small text scuzzman LQ Suggestions & Feedback 1 03-28-2005 02:14 AM
how to compare 2 text files by using php code antony_csf Programming 3 10-14-2004 05:52 AM
how change text (and background) color within the bash shell? Xavius Linux - Newbie 4 03-29-2004 02:21 PM


All times are GMT -5. The time now is 08:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration