Accessing session variables with php

I am trying to access the  session variable  $_SESSION['MM_Username']  in one of my php pages, but it is somehow showing empty (i.e it does not contain the username that was entered during login).
I checked and confirmed that my login.php function is properly setting the MM_Username session variable by echoing it  from the login function.
So why can't I read it from another php file in the same session?  Do I need to do something else before the session variables can
be properly read from any php file in the same session?  Any help would be appreciated.

Here is a test code I am using to access the session variable $_SESSION['MM_username']  from  the php page  test.php. But it is not working.
I get an empty string all the time for $username. Can any one see something wrong with this code?
<?php require_once('Connections/MyTestingConn.php'); ?>
<?php session_start(); ?>
<?php
$username = "-1";
if (isset($_SESSION['MM_username'])) {
  $username = $_SESSION['MM_username'];
  echo $username;
else
   echo "Eror: can not access session variable";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
</body>
</html>

Similar Messages

  • Creating a session variable with PHP

    Can anyone offer me a PHP script that creates a session
    variable? The Dreamweaver CS3 Help documentation offers coding
    samples for ColdFusion and ASP but not for PHP. I tried this
    without success:
    "$_SESSION['usermail']= $_POST['sub_email'];" in which I am
    trying to capture an email address from a form and save it to use
    in a confirmation email to a new subscriber. Any help would be
    sincerely appreciated.
    [email protected]

    I use this -
    <?php
    if (!isset($_SESSION)) {
    session_start();
    ?>
    at the top of the page, and then this within the code block
    where you are
    processing the form's data -
    $_SESSION['usermail']= $_POST['sub_email'];
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Jugdish" <[email protected]> wrote in
    message
    news:gb8aov$691$[email protected]..
    > Can anyone offer me a PHP script that creates a session
    variable? The
    > Dreamweaver CS3 Help documentation offers coding samples
    for ColdFusion
    > and ASP
    > but not for PHP. I tried this without success:
    > "$_SESSION['usermail']= $_POST['sub_email'];" in which I
    am trying to
    > capture
    > an email address from a form and save it to use in a
    confirmation email to
    > a
    > new subscriber. Any help would be sincerely appreciated.
    > [email protected]
    >

  • Access session variable inside AM module

    Is there any way to access session variable inside AM module custom function?
    I created one client interface function in AM and want to access one session variable value inside AM custom function.
    Please suggest.
    Thanks

    Hi
    here i need help to find out right approach,my use case are below
    1.User will login thorough SSO .
    2.Based on used id i need to display user data in table form.
    3.User-id will need to display in right corner of page template ( JSF page with this page template)
    4.user can update/create new table data by pressing update/createinsert button.
    5.Once user press the create new request button,one empty row will popup which have user-id filled automatically (used-id who logged in) and will read only ,so that once user commit the data,DB can update/insert the data with that user-id
    so far i have done point 1,2,4 and 5 like
    1.i created AM preparesession and store the use id.
    2.i have putted whereclause in AM for particular VO and run execute query and able to see particular user data,who logged in.
    4.created servicemethod for createinsert in AM and exposed it ,and set used-is table attribute which i got in AM preparession .Now i am able to see new row with user-id in one column in read only form when
    Is this the right approach ? and now i am not able to do step 3 so how to display same user-id in pagetemplate as this value is available in AM only.

  • Access Session variable inside Transaction

    Hi All,
    Is it possible to access session variables inside Transaction.
    Create session variable.
    Update session variable value
    acccess Session variable.
    (user session)
    Regards,
    Sachin

    Hi Sachin,
    Here is the snapshot:
    1. Take session variable in a local JS variable in HTML page.
    2. Create a transaction with a input type variable in Transaction Properties.
    3. Create a Xacute query and link the above transaction.
    4. Creata a iCommand applet on HTML page and link the query template:
    <PARAM NAME="QueryTemplate" VALUE=".../QueryName">
    Call the function in the below way in HTML:
    Applet.getQueryObject().setParam(1,vaiable)
    So, the session variable will go to TRX (BLT) and perform the operations as per your need..
    You can pass it to other TRX by the same way.
    To fetch the value: Create output type variable in TRX 2. Create Xacute query.
    Get the value with : Applet.getValue(1,1)
    Hope it is useful.
    Best Regards,
    Kedar

  • Accessing session variables PHP

    I am trying to access a session variable from a log in form (using the Log In User Server Behavior) and am lost. I simply want to display the users information in the target page. I read in another discussion that I had to bind the variable to the target page, which I did, but that didn't fix it.
    Please help.
    Here is my loginFormAction code:
    <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
      session_start();
    $loginFormAction = $_SERVER['PHP_SELF'];
    if (isset($_GET['accesscheck'])) {
      $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    if (isset($_POST['email'])) {
      $loginUsername=$_POST['email'];
      $password=$_POST['password'];
      $MM_fldUserAuthorization = "";
      $MM_redirectLoginSuccess = "owner.php";
      $MM_redirectLoginFailed = "register.php";
      $MM_redirecttoReferrer = false;
      mysql_select_db($database_petriever, $petriever);
      $LoginRS__query=sprintf("SELECT email, password FROM owners WHERE email=%s AND password=%s",
        GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
      $LoginRS = mysql_query($LoginRS__query, $petriever) or die(mysql_error());
      $loginFoundUser = mysql_num_rows($LoginRS);
      if ($loginFoundUser) {
         $loginStrGroup = "";
        //declare two session variables and assign them
        $_SESSION['MM_Username'] = $loginUsername;
        $_SESSION['MM_UserGroup'] = $loginStrGroup;      
        if (isset($_SESSION['PrevUrl']) && false) {
          $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
        header("Location: " . $MM_redirectLoginSuccess );
      else {
        header("Location: ". $MM_redirectLoginFailed );
    ?>

    Wherever you want to display the logged-in username simply place this on the first line of a .php page to start the session:
    <?php session_start(); ?>
    Then place this code wherever you want to display the username:
    <?php echo $_SESSION['MM_Username']; ?>

  • Access session variable in Java Function in JSP

    Hi Experts !!
    I am developing an application using STRUTS MVC...
    Very sorry if u have problem understanding my question, i ll try to improve... and sorry if i can't post codes here
    Basic question is ....
    I want to open a word document on pageLoad of JSP, the word document is not a single document, there is a form in which there is a "name" and "template" whenever user clicks on a button there is one action attached to it which creates a copy of that template in a different folder.. on the next page OnLoad i want to open that particular document. for that i have created a variable and also have set in the session, just want to access it in the below code.
    I have a formbean in which i have a variable, the scope is session, that variable i have put it in session also. but i want to access that variable in a "java function" in JSP so that "onLoad" page that function should work.
    JSP---
    <script type="text/javascript">
    function openDocument() {
    var w = new ActiveXObject("Word.Application");
    var docText;
    var obj;
    var a;
    if (w != null) {
    w.Visible = true;
    obj = w.Documents.Open(I HAVE TO ACCESS THAT VARIABLE HERE);
    </script>
    FORMBEAN----
    public class CreateSOWFormBean extends ActionForm {
    private String workflowName;
    private String comment;
    private String sowTemplate;
    private String sowFileCreated;
    public String getSowFileCreated() {
    return sowFileCreated;
    public void setSowFileCreated(String sowFileCreated) {
    this.sowFileCreated = sowFileCreated;
    sowFileCreated is the variable that i have accessed in session and that value i have to pass in that function in JSP....
    I am aware of something like
    obj = w.Documents.Open(<%'sowFileCreated'%>);
    but i m not sure how to write....
    Plz help.....

    If you're working under a framework like struts you should definitely be using JSTL tags rather than scriptlet code to access variables within the page. With JSTL code <% codes can be almost entirely avoided.
    To transfer a value from a Servlet to a JSP don't use a session variable, use a request attribute. Session variables should only be used when values have to survive from one transaction to another.
    You can write something like:
    obj = w.Documents.open('<c:out value="${openURL}"/>');in the Javascript portion of your JSP.
    Just beware of potential problems with quotes. The coresponding code in the Servlet would be like:
    request.setAttribute("openURL", openUrl);

  • How to generate a random session variable in php

    i want to generate a random session variable and insert the variable in a mysql record to use later to validate an account set up.
    person fills out form to create account and submits; inserts form information in mysql record.
    i want the random variable to be inserted from a hidden field and the page sends an email with a link to click on to compare the variable to validate the user.
    Not sure how to generate a random session variable and get that to the hidden field value to be inserted with the other form information.
    thanks for your help,
    Jim Balthrop

    To insert the key I would personally do something like...
    $key = md5($username . $password . $salt);
    Insert that into your MySQL database, then send them a email with it, my next code shows how to activate it.
    This is to activate the account.
    <?php
    $key;
    $errors = array();
    if(isset($_GET['key']){
         $key = $_GET['key'];
         $sql = 'SELECT * FROM users WHERE key = \'' . $key '\' LIMIT 1';
         $result = mysql_query($sql) or die(mysql_error());
         if(mysql_num_rows($result)){
              $sql2 = 'UPDATE users SET active = 1 WHERE key = \'' . $key '\' LIMIT 1';
              $result2 = mysql_query($sql2) or die(mysql_error());
              if($result2){
                   //successfully activated account
              else{
                   //Something Went Wrong!
         else{
              $errors[] = 'Invaild Key, Please try again!';
    else{
         $errors[] = 'Invaild Key, Please try again!';
    ?>

  • Session variable with list of availalble dashboards?

    Hello,
    Is it possible to populate a -row-wize?- session variable (using an initialization block & system variable :USER) with a list of dashboards the user will have access to (like the list of dashboards displayed at the top of the webportal) once he has logged on?
    My customer has stated the requirement to provide each user with a default 'Home' dashboard (different from 'My dashboard') that will provide an overview of the available dashboards, accompagnied by a description of each dashboard.
    Of so, what would be the syntax to be used?
    Thanks!
    Randall

    Hi Randall,
    The BI-server isn't aware of the presentation server. This means it doesn't know to which dashboards a user has access. What you could do is populate a table in the DB and use guided navigation to give access to dashboard.
    regards
    John
    http://www.obiee101.blogspot.com/

  • Accessing session variable in Flex.

    Hi All,
       I'm using RemoteObjects for accessing data and using Spring BlazeDS. How to retrieve 'session' variable values in Flex?
       Main application which is calling different .mxml files. It first invokes login(login.mxml) page with successful user credentials it will display home(home.mxml) page and I have search(search.mxml) pages.
        In case user session timeouts then I'd like to send user request to login page for login.(say user is in search page and where he left for 30 minutes, after then when user clicks anything on search page, it should redisplay login page because session timeout is set to (25 minutes).  How to do this Felx??
       Thanks in advance.
    Regards,
    Sharath.

    More detail solution will be found in the help.
    Look for the following string in your local help (in flex builder): Communicating with the Wrapper.
    You will probably find that you have to do something like the following:
    a) call from flex to the wrapper page javascript function.  (this would be a polling operation, run on a timer event (say) once every minute.
    b) the javascript function you call conducts an Ajax call to determine the current session state.
    Note that the above will likely keep your session state alive.
    Another possibility is to pass in the value of your session timeout via a FlashVars variable.
    Again, in a timer function run every minute, invcrement a local counter.
    When local counter equals session passed in, then you might assume that the session has timed out.
    IHTH.
    Cheers

  • Access Session variable across the hosts

    Hi,
    I am facing an issue. Please find the following scenario.
    I have a login page which is under a secure host. When the login is successfull, the control will be directed to a non secure host, where I have to access a session variable which is set in the LoginPage (which is a secure host). Can I do this?
    Can any one help me in solving this
    regards,
    Jo
    Message was edited by:
    JoshyzJava

    To retreive a varable from another JVM or indeed another host you would need to use Remote Method Invokation (RMI), calling getSecureSessionID() or isSessionOK(sessionID) or whatever from the programme running in the remote JVM.
    The method in general is floored unless the RMI is secure, I have no experience of encrypting this but I'm sure it is possible. You're non-secure-host must have the funcionality to communicate with the secure-host securly, otherwise the secure-host is not secure.
    Bamkin

  • Accessing session variables....urgent

    Hi,
    i have a session variable in my JSF application that stores the userId when a user logs in!!
    i need to access the session variable in a method in the bean.
    can HttpSession and HttpServletRequest objects be accessed in the managed bean
    help me with the code please.....itzz urgent

    see http://forum.java.sun.com/thread.jspa?forumID=427&threadID=545939

  • Accessing session variables

    Hi ,
    I have session variable defined using portals (forms or plsql portlets).
    Can i access these variables using jsp portlets ??
    This is an urgent requirement ..
    Regards,
    Vijaya

    "145822",
    If your application with application id 100, for example, uses a common authentication scheme with application 200 (using the same cookie name in the case of an HTML DB style authentication scheme), then the two applications can run in the same session. A potential benefit of this, even if the two apps are not intricately related, is that the user has only to authenticate once per new session and will have access to both apps. If you set it up this way, then app 100 can access app 200's items in the same session using this function from within app 100:  htmldb.application.fetch_app_item(p_item=>'ITEM_NAME',p_app=>200);Scott

  • Using Session Variable with Conditional Formatting Filter

    Hi,
    I'm trying to add a condition to my report in order to flag all opportunities that have a close date that is in the past. The way I'm trying to do this is by adding a condition to say when close date is less than current_date, flag the column with an image.
    Issue I'm having is that the filter window within conditional format tab appears to not have the session variable option as you do when you create a filter on a column the normal way. A colleague told me to use an SQL expression, but again this option seems to be unavailable too within the conditional format tab.
    Can anybody assist please?
    Thanks

    Create a new column and write a CASE WHEN condition like case when close date < current_date then 'Y' ELSE 'N' END.
    Then on your actual date column, you can do conditional analysis based on the newly created column for values having Y then the image.
    finally, you can hide the newly created column.

  • Problems accessing session variables from a pop-up

    I am working on a webapp and I when I click on a certain button I need to have a pop-up appear that will either prompt a user to enter log-in info if they haven't already, otherwise the pop-up just needs to display a report. Users can navigate around on the main page and select various reports so multiple pop-ups could possibly be opened. When a user logs in I save the login info in session variables, but for some reason whenever I click to have another pop-up open it always says that my session variables are null. Is there a way to have more global session variables so that multiple windows (the pop-ups) can touch session variables? Would there be a way to pass the login info in session variables back to the main page and then pass those session variables back out to each pop-up that opens? Thanks so much.

    Have you got session cookies enabled?
    The most common way to keep track of the session id is via a session cookie.
    This cookie gets shared by all windows of the same browser session.
    You are opening these pop-up windows with window.open?
    Print out the session id <%= session.getId() %> on each page to see if it is the same.
    Cheers,
    evnafets

  • SESSION VARIABLE in PHP

    I am new to web applications, but for what I need is to know
    how to use session variables. When a user logins I want thier
    information stored so when they visit my account they are able to
    see thier information and not someone elses. Any help should be in
    PHP format. Thank you in advance.

    prashi123 wrote:
    > I am new to web applications, but for what I need is to
    know how to use session
    > variables. When a user logins I want thier information
    stored so when they
    > visit my account they are able to see thier information
    and not someone elses.
    > Any help should be in PHP format. Thank you in advance.
    http://www.php.net/manual/en/features.sessions.php
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

Maybe you are looking for

  • How to delete storage off an external hard drive

    i have an imac made in 2006 with 20in screen and web cam i brought an external hard drive about 6 months ago. Now the external hard drive is full now it want let me in my computer all the way . It tell me to learn more and i click it but the google t

  • Movie subtitle trouble...

    Hello - After adding subtitles to a movie file (using Submerge), it will play fine in Quicktime, but once imported to and played in iTunes (10.7), the subtitles don't show up. This problem has started recently - I was previously able to play the subt

  • I can't link up the play button in Encore

    I just want one button, THE PLAY Button. The project has no errors and will allow a build. Then When I add a button It will not link.

  • Photoshop CC: Calling PIUGetInfoByIndex causes an exception when searching documents

    I have a function call in an automation plug-in that searches through the documents opened in Photoshop and attempts to get the name of each document (to compare it to a name that is passed in).  When this piece of code gets hit, if Photoshop has two

  • Click on iDVD, but nothing happens.

    I could use a helping hand. I have created a movie in iMovie. When I went to create a DVD using iDVD, nothing happened. Then, I tried on clicking (double) on the iDVD icon. Again, nothing happens. I tried the other tricks, like highlighting the appli