?
Solved

Alternate for Session_register()

Posted on 2009-12-28
14
Medium Priority
?
1,374 Views
Last Modified: 2013-12-12
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".
0
Comment
Question by:Papote
  • 5
  • 4
  • 2
  • +2
14 Comments
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26130582
hi ,

try to use in such method it might help u

if(!isset($_SESSION['myusername'])){
      session_register("myusername");
      }
0
 

Author Comment

by:Papote
ID: 26130605
I am actually looking for an alternative to using the session_register(); statement as it is being phased out in newer PHP releases.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Papote
ID: 26130612
The original post is incorrect; it is when I use $_SESSION['myusername'] = $myusername; that I get the "Undefined index: myusername" error message.
0
 
LVL 2

Assisted Solution

by:animesxplosion
animesxplosion earned 664 total points
ID: 26130632
<?php
session_start();
....
....
$_SESSION['myusername'] = $myusername;
...
...
?>
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26130769
hi,


if(!isset($_SESSION['myusername'])){
      session_register("myusername");
      }
else
{
$_SESSION['myusername'] = "the value";
}
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26130809
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
 

Author Comment

by:Papote
ID: 26131550
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
 
LVL 6

Accepted Solution

by:
hexer4u earned 668 total points
ID: 26131993
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
 

Author Comment

by:Papote
ID: 26132336
I used session_start(); before echoing and still get undefined index.
0
 
LVL 6

Expert Comment

by:hexer4u
ID: 26132354
make sure the value inside ' ' is the same on all pages. also, is it on a subdomain?
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 668 total points
ID: 26132457
"...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
 

Author Closing Comment

by:Papote
ID: 31670361
Seems I did leave out session_start(); from the checklogin.php script, every other page did have it.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

755 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