Solved

Problem with session_register

Posted on 2003-10-27
3
506 Views
Last Modified: 2013-12-13
I creating session variable with this code :
<?php
  session_register("var_x");
  $var_x = "123456";

  print(" session_id() . "<BR>\n");
  print("Session variable is : $var_x");
?>

I get nothing when read that variable with this code :
<?php
  session_start();

  print("SID : " . session_id() . "<BR>\n");
  print("Session variabel is :   <BR>\n");
  print($var_x);
?>

SID is appear but print($var_x) doesn't print anything, What's wrong ?
Thanks.
0
Comment
Question by:shanyuen
3 Comments
 
LVL 2

Expert Comment

by:errows
Comment Utility
before registering your variable, start it as well.

<?php
  session_start();
  session_register("var_x");
  $_SESSION["var_x"] = "123456";
0
 
LVL 6

Accepted Solution

by:
DoppyNL earned 50 total points
Comment Utility
You con't have to use session_register anymore! it may be removed from future versions of PHP so you're better of not using it anymore.

You can do it like this:

<?php
session_start(); // start the session
$_SESSION['myvariable'] = 123; // store "123" in "myvariable" in the session
?>

on each next page you can use $_SESSION['myvariable'] to use that variable (make sure you used session_start() first!)
0
 
LVL 5

Author Comment

by:shanyuen
Comment Utility
I had fix it myself.
The problem is in php.ini
session.save path still "/tmp"
Then I change to my local drive.

Anyway, thanks for the information.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

743 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