Solved

Get php to remeber a variable value

Posted on 2003-11-17
4
387 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 50 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

728 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