Alternate for Session_register()

I am using PHP 5.3 and have a code that saves the username using session_register("myusername"). I know that it shouldn't be used but when I use session_register("mypassword"); I get an error stating: "Undefined index: myusername".
PapoteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
InsoftserviceCommented:
hi ,

try to use in such method it might help u

if(!isset($_SESSION['myusername'])){
      session_register("myusername");
      }
0
 
PapoteAuthor Commented:
I am actually looking for an alternative to using the session_register(); statement as it is being phased out in newer PHP releases.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
PapoteAuthor Commented:
The original post is incorrect; it is when I use $_SESSION['myusername'] = $myusername; that I get the "Undefined index: myusername" error message.
0
 
animesxplosionCommented:
<?php
session_start();
....
....
$_SESSION['myusername'] = $myusername;
...
...
?>
0
 
InsoftserviceCommented:
hi,


if(!isset($_SESSION['myusername'])){
      session_register("myusername");
      }
else
{
$_SESSION['myusername'] = "the value";
}
0
 
InsoftserviceCommented:
hi,

for undefined index u can try

if(!isset($_SESSION['myusername'])){
      $_SESSION("myusername") = "NULL";
      }
else
{
$_SESSION['myusername'] = "the value";
}

http://www.phpbuilder.com/board/showthread.php?t=10353837
0
 
PapoteAuthor Commented:
This is part of a login script. I echoed the $_SESSION['myusername'] and $myusername and they both do save the variable, but once I move to another page it isn't defined.
0
 
hexer4uCommented:
you have to begin the page with session_start(); in order to have access to session variables.
just write <?php session_start();?> at the beginin of all files you need acces to session variables.
animesxplosion wrote a way to start a session and write a session variable.
use the if - isset(xxxxx)  condition to check if a session variable exists. (xxx is the $_SESSION['variable'])
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
PapoteAuthor Commented:
I used session_start(); before echoing and still get undefined index.
0
 
hexer4uCommented:
make sure the value inside ' ' is the same on all pages. also, is it on a subdomain?
0
 
Ray PaseurCommented:
"...once I move to another page it isn't defined."

Please post a link to the test pages where this is happening.  Also, please post the code that is causing it.  And check to see that your browser is accepting cookies.

"I used session_start(); before echoing..."

But did you use session_start() before ANY BROWSER OUTPUT AT ALL - including whitespace?  If not, the session cookie cannot be set.

Show us those things and we can certainly help you get past this issue.  Best, ~Ray
0
 
PapoteAuthor Commented:
Seems I did leave out session_start(); from the checklogin.php script, every other page did have it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.