FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP noob problem





xavax
I'm quite new to PHP etc. and need help. My problem is this:
I've been using HTML forms to send info to PHP using Post, which works fine, but now I need to send more info which the user can't change.
I need a way to make a field unchangable or another way to send information to a PHP page.
Thanks Wink
rvec
you can use sessions. All other info can be changed by a user.

Sessions can be used like this:
start every page in which you might want to use sessions like this:
session_start();
Make sure that's before any output is send to the browser, so don't put any echo or html before it.

and then you can use the $_SESSION superglobal.
So for example:
Code:
<?php
session_start();
$_SESSION['foo'] = 'bar';
?>

and in another page the user visits later (will work as long as the user didn't close the browser and has visited the first page or any other page on your site with sessions in the last 5 min).
Code:
<?php
session_start();
echo $_SESSION['foo'];
?>
xavax
Thanks. Wink
kv
Or if those values are form specific, you can use hidden variables in the form. The value can be set by php dynamically.
rvec
kv wrote:
Or if those values are form specific, you can use hidden variables in the form. The value can be set by php dynamically.

Those can be changed by users easily. Not by normal users, but those who know a bit more about the net can easily do so. A hidden form can be used for simple stuff like on which topic you are replying, or which product you want to bid on, but for info the user shouldn't be able to change (is the user logged in, did he pay, how much will the products the user chose cost, is the user an admin) you should never use hidden forms, and always use sessions.
Fire Boar
If you need the information to persist after the user closes their browser then you should probably use a database for this sort of thing. Otherwise session variables are the way to go.
rvec
Fire Boar wrote:
If you need the information to persist after the user closes their browser then you should probably use a database for this sort of thing. Otherwise session variables are the way to go.
or cookies.
kv
rvec wrote:
Fire Boar wrote:
If you need the information to persist after the user closes their browser then you should probably use a database for this sort of thing. Otherwise session variables are the way to go.
or cookies.


No, not cookies if you want the value to be available after the user closes the browser, since cookie values are stored in browser client.
rvec
you will get the values again when the user comes back. So stuff like login info, to auto-login him the next time could be stored in a cookie. Or settings on the site, like the colours he likes to see.
DjMilez
rvec wrote:
like the colours he likes to see.

I lol'd at that for some reason....

Also, I guess sessions are the best choice...
rvec
DjMilez wrote:
rvec wrote:
like the colours he likes to see.

I lol'd at that for some reason....

Also, I guess sessions are the best choice...
There is not one good choice, it all depends on what info you need saved, how much of that info, how sensitive the info is, if the users knows/may know the information, how important the info is for your application, how much you use the different types of databases (you won't make a mysql db for 3 settings only).... and of course which ones you like more Razz
pawelabrams
to sum up:

Hidden fields:
to send data user doesn't want to change (I think that's not your case)

Cookies:
auto-login, maybe color-scheme or simple settings that doesn't make any harm when changed...

Session:
sensitive, but short-term data - items user wants to buy, price of them, login, checksum of password, is the user logged in etc.

Database:
sensitive, long-term data, like history f transactions, user profile, passwords, ranks (admin, user, manager etc.)...
Related topics
Php, mime_content_type() problem
[SOLVED] PHP is not working
php security problem
PHP Login Problem
What is useful way in this php+mysql problem?
Introducing myself
problems for indexing php pages in google.
[PHP] classes problem..
question aux codeurs ! php noob InsiDe!!
PHP script problem
Stats problem - php execution problem (MOD Assist Required)
php msql problem
php mail(); problem... half fixed?
PHP Includes Problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.