Solved

Get php to remeber a variable value

Posted on 2003-11-17
4
379 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
  • 3
4 Comments
 
LVL 2

Expert Comment

by:neele
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now