Jump to content

[SOLVED] just a little problem


jeppers

Recommended Posts

i am trying to write some simple code but i am not as sure if its the code or my browser...

 

what i am trying to do is write some code which will allow the users to change there setting i.e font color, bg_color...

 

i have written 2 x script but when i run them i am not sure if the browser stopping the cookies or my scripts..

 

could you have a look and see what you think..

 

 

<b>The form which is used to customizes </b>

<?php //customize.php

//address error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

$cookies = FALSE; // cookies have not been sent 

//handle form, if it has not been submitted 
if (isset ($_POST['submit'])) {

//send the cookies 
setcookie ('bg_color', $_POST['bg_color']);
setcookie ('font_color', $_POST['font_color']);

$cookies = TRUE; // cookies have been set 

}// end of submit if
?>

<!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=iso-8859-1" />
<title>Custermize your settings</title>
</head>

<body>
<?php
//if cookies have been sent print htis message 
if ($cookies) {
print '<p>Your settings have been entered! Click <a href="view_settings.php">Here</a> to back to the main page.</p>';
}
?>

<p><strong>use this form to set your preferences:</strong></p>
<form action="customize.php" method="post">
<select name="bg_color">
<option value="">BackGround Color</option>
<option value="#ffffff">White</option>
<option value="#00cc00">Green</option>
<option value="#0000ff">Blue</option>
<option value="#cc0000">Red</option>
<option value="#000000">Black</option>
</select>
<select name="font_color">
<option value="">Font Colour</option>
<option value="#ffffff">White</option>
<option value="#00cc00">Green</option>
<option value="#0000ff">Blue</option>
<option value="#cc0000">Red</option>
<option value="#000000">Black</option>
</select>
<input type="submit" name="submit" value="Set My Preferences" />
</form>


</body>
</html>

 

The code which catches the data from the cookies

<!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=iso-8859-1" />
<title>View Your Setting</title>
<style type="text/css">
body {
	background-color:#FFFFFF;
	color: #000000;
<?php // view_setting.php

//address error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

//check for a bg_color value
if (isset ($_COOKIE['bg_color'])) {
print "\t\tbackground-color:{$_COOKIE['bg_color']};\n";
}else{
print"\t\tbackground-color:#ffffff;\n";
}

// Check for a font-color value
if (isset($_COOKIE['font_color'])) {
print "\t\tcolor: {$_COOKIE['font_color']};\n";	
}else{
print"\t\tcolor: #000000; \n";
}
?>
}
</style>
</head>

<body>
<p><a href="customize.php">Customize you settings</a></p>
<p><a href="Reset.php">Reset Your settings</a></p>
<p>
<p>yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda</p>
<p>yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda</p>
<p>yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda</p>

</body>
</html>

 

any help will be great full...

 

Link to comment
Share on other sites

by the looks of

setcookie ('bg_color', $_POST['bg_color']);
setcookie ('font_color', $_POST['font_color']);

 

I would recommend using $_SESSIONS, will work if cookies are on or not

and besides theres a problem with the cookies....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.