Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get php to remeber a variable value

Posted on 2003-11-17
4
Medium Priority
?
391 Views
Last Modified: 2013-12-13
How do I get PHP to remember a variable value when submitting a form the second (0r third)
time round?
0
Comment
Question by:AntonBotes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Expert Comment

by:neele
ID: 9768297
You can use session object to store those values.

Storing value to session.
session_start();
$_SESSION['user_id'] = $userid; //storing the $userid value to session
$_SESSION['UserName'] = $username; //storing the $username value to session

To retrieve (sample ONLY)
====================
session_start();
if($_SESSION['user_id']) //check first in case..
$ID = $_SESSION['user_id']) //set it to variable $ID



0
 

Author Comment

by:AntonBotes
ID: 9770041
Comment on 'neele':

If I use 'session_start()' , it complains about '....cookie already sent...' and '..cache limit already sent'...'
If I don't use 'session_start()', it complains about '...undefined variable _SESSION...'.
0
 
LVL 2

Accepted Solution

by:
neele earned 150 total points
ID: 9771024
check in your php.ini :
session.auto_start = 1 //set to 1 so it auto-start the session.
session.save_path = C:\php\sessiondata //set the path for storing the session..data
session.use_trans_sid = 1

Try checking the setting..n see whether it works..

AND do place session_start(); at the very beginning of your code. If u r having other code..
in between..

e.g.
<?php
session_start();
....
....

?>


hope it helps
0
 
LVL 2

Expert Comment

by:neele
ID: 9771046
n Share this site with U. I think is quite a good reference :)

http://www.sitepoint.com/article/319/4
on php session
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question