Connecting Tech Pros Worldwide Forums | Help | Site Map

set values once

julian_m
Guest
 
Posts: n/a
#1: Sep 30 '05
let say that i want to allow someone (the site admin maybe) to chose
certain configuration values, for instance

* number of products per page
* picture widht
* back color
....
....

Right now, i just have all those info in a php page, so it can't be
modified
$number of products_per_page = 20;
$picture_widht = 2;
$back_color = #FFFFFF;

I could keep this info in the database, but i should read it every time
a page is rendered... (open connection, query, close conn)

What would be the best way to do what i'm need? Is there any chance to
"read once, keep value for ever" ?

regards - jm


pizzy
Guest
 
Posts: n/a
#2: Sep 30 '05

re: set values once


//jm,

//I would use sessions or cookies... or you could turn on globals but i
wouldn't recommend this...

//example:

//////////////////////
//(index.php)
///////////////////////
session_start();
$back_color = #FFFFFF;
$_SESSION['back_color'] = $back_color;

//////////////////////
//(nextPage.php)
///////////////////////
session_start();
<body bgcolor='<? echo $_SESSION['back_color']; ?>'>


// I hope this helps
// from,
//
// pizzy

julian_m
Guest
 
Posts: n/a
#3: Sep 30 '05

re: set values once


But this is mainly what i'm doing right now. Note that #FFFFFF is
"static" and can't be changed without have access to .php file...

I should try to see how products like os_commerce or the like solve
this kind of things...

pizzy
Guest
 
Posts: n/a
#4: Sep 30 '05

re: set values once


right... you want to story users info so that when they log back in
their settings are kept... use a database for this and query as soon as
they login. then use my examples to display his or her values.

Colin McKinnon
Guest
 
Posts: n/a
#5: Sep 30 '05

re: set values once


julian_m wrote:
[color=blue]
> let say that i want to allow someone (the site admin maybe) to chose
> certain configuration values, for instance[/color]
<snip>[color=blue]
>
> I could keep this info in the database, but i should read it every time
> a page is rendered... (open connection, query, close conn)
>[/color]

So put it in a file then (although it's not *that* much of an overhead using
the DB):

file_put_contents($config_file, serialize($options));

and

$options=unserialize(file_get_contents($config_fil e));

C.
Closed Thread