Servlet/PHP Session Variables

Hello Everyone,
I am running an servlet that requires authentication. The authentication is done by a PHP program, while the heavy lifting is done by a servlet. How do I pass a session variable from my php to my servlet so that my servlet knows the user is allowed. I have tried
Object done = session.getAttribute("loggedIn");
with "loggedIn" being set by my php file, but done is always null. Any help is greatly appreciated especially if it is cookie free.
Sincerely,
Chem E

You could consider the following solution: on click of the link, fire a specific Ajaxical request from the server where PHP runs to the server where Java runs to obtain an lengthy and unique key which expires within a few seconds, use JS+DOM to add that key as a query parameter to the link value and after opening the link let the Java side determine the key and handle accordingly.
You only need to write code so that it is hack safe.

Similar Messages

  • Listener Servlet storing session variables

    hi all,
    i have a listener servlet class which is performing tcp/ip socket communication. now i want this class to store session variables. i have tried to implement it and access the stored variable values from other pages, but i am unable to access them, which tells me that the servlet is not storing the values in the first place.
    any help. thanks in advance.

    can you post some code.
    it is also posible that those values are stored in a different session that in the one you try to read from

  • Help with php session variables

    I am using Dreamweaver 8 to set up a dynamic app with PHP and
    MySQL. I want the code that the user logs in with ('UPN') to be
    stored as a session variable so that recordsets on subsequent pages
    can be set to display personalised data.
    I have set the session variable like this: $_SESSION['UPN'] =
    'UPN' (UPN is the name of the form textfield, also set as the
    username for logging in)
    On the data page, I have called the variable like this:
    $query_Recordset1 = ("SELECT pupils.pupilID, pupils.UPN,
    pupils.forename, pupils.surname FROM pupils WHERE UPN = '" .
    $_SESSION['UPN'] . "'");
    The recordset returns nothing- the dynamic table returns ony
    the column headings (both as headings and immediately under where
    you would expect the data to be).
    Can anyone help?
    Thanks

    On Wed, 17 Oct 2007 11:43:04 +0000 (UTC), "denman"
    <[email protected]> wrote:
    > I have set the session variable like this:
    $_SESSION['UPN'] = 'UPN' (UPN is
    >the name of the form textfield, also set as the username
    for logging in)
    Your code assigns the literal string UPN to the session
    variable. If
    it's coming from POSTed form data, you'd need to do it like:
    $_SESSION['UPN'] = $_POST['UPN'];
    Gary

  • PHP Session Variable

    When using the PHP variable $_SESSION['idk'], what is the significance to the string 'idk'?
    I have been playing around with a login script, and I have seen some people throw 'user_login' or 'login' or 'user' and I figured it was just a way of labeling it essentially. But then I happened across a post where someone was generating and using a random string with the Session variable.
    Does this string have to be different for every user logging into a website? If not, what is the purpose of generating a random string to use in conjunction with the Session variable?
    Maybe any insight into different uses of the Session variable would be helpful as well.
    Thanks!

    With this post we're launching a new feature in the community: a look at a few of the day's top stories or issues. Let us know what you think – and where in the community you'd like to find these topics on a daily basis.Browser woes – Chrome 44 was released yesterday, but a "feature" of the latest softwarebroke some WordPress pluginsand many plugin developers have released updates to fix the problem. Meanwhile, HP's Zero Day Initiative disclosedfour zero-day vulnerabilitiesin Internet Explorer."Pocket dialing" privacy – A federal appeals court in Ohio hasruledthat anyone who accidentally "pocketdials" someone loses their right to privacy because they "lack a reasonable expectation that their conversations would not be intercepted, which is a prerequisite for protection under Title III."Bloomberg explains the background of the caseand...

  • Problem with PHP Session Variables

    Hello all,
    I am in the process of converting an internal company site
    from ASP/Access to PHP/MySQL. All was going well until I started
    working with User Authentication involving access level. No matter
    what I do I can't seem to shake the MM_UserGroup variable.
    I have a link on the main page that is variable dependent on
    the access level of the user. If the user is logged in as a
    Supervisor they should see a link to the supervisor control panel.
    If logged in as a user or not logged in at all, they should see a
    link to the supervisor login page.
    I have put a Restrict Access function on the supervisor
    control panel and it functions as usual. When logged in as a
    supervisor I have access. When logged in as a user or not logged in
    at all, I don't.
    It seems that my homepage always sees the MM_UserGroup
    variable set as "Supervisor". I can log in as a user, close the
    browser, restart the server, everything and it always sees the
    variable set as "Supervisor". Just to make sure I wasn't crazy I
    put in an echo function so that it would display "MM_UserGroup". It
    always says "Supervisor" no matter what I do. Using echo to show
    the MM_Username variable, it functions as expected. When I close
    the browser and reopen it, I get a nice error as expected because
    there is no one logged in at that time. I still see "Supervisor"
    staring me in the face though.
    I'm sure it's something simple that I'm missing, not being an
    experienced PHP user.
    Any thoughts from the experts out there?
    Thanks in advance,
    David

    aidan81 wrote:
    > immediately upon login for a user, I see "User" printed
    as expected. Once I
    > use this page to edit their status, I am redirected back
    to the main page as
    > expected and immediately see "Supervisor" staring at me.
    If I then revisit the
    > user's edit page, it now says "Supervisor". Seems that
    something screwy is
    > going on and I'm at a loss....
    It sounds as though you are reassigning the value of the
    variable. If my
    memory serves me right, ASP uses a single equal sign to
    perform a
    comparison. PHP uses two.
    Check that you don't have something like this in your code:
    if ($_SESSION['Authority'] = 'Supervisor') {
    // do something
    That will assign Supervisor to $_SESSION['Authority'].
    It should be this:
    if ($_SESSION['Authority'] == 'Supervisor') {
    // do something
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • How to use session variable in JSP function  & How to use both JSP  Servlet

    Hi,
    I am new to JSP and servlets
    Still I am devloping a website in JSP. I am not mixing JSP with servlets, but I do create Java files for bean, logic and database works.
    I try to keep the hard coding part out of JSP.
    I dont how to use both JSP and Servlets in combination.
    Hence If needed I write some functions in JSP.
    but it gives me error
    +<%! public void abc()+
    +{+
    int intUserId = Integer.valueOf((Integer) session.getAttribute("MySession_UserID"));
    +}+
    +%>+
    Saying cannot find symbol session
    1) So can u please tell how can I access session variables within JSP function
    2) And also give me some links/tutorials about useing both JSP and Servlets in combination.
    Thanks
    Venkat

    The application architecture when you use Servlets and JSP in a standard MVC pattern is explained here (under the heading "Integrating Servlets and JSP Pages") and here ...

  • Help with session variable please - CS5.5 PHP

    Hi all,
    I am needing a little assistance with using a session variable and hope that someone may point me in the right direction.
    I have created a PHP page that uses the Dreamweaver 'User Authentication' feature, and the basics of this works fine, directing a user to the correct pages depending on whether they are or are not a valid user. I would like however to personalise the 'valid user' page with the persons Username as entered in the User Authentication table....a seemingly simple task using a session variable, but one that I just don't seem to be able to get working!
    The code generated for the UA on page 1 is as follows:
    <?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['txtfirst_name'])) {
      $loginUsername=$_POST['txtfirst_name'];
      $password=$_POST['txtsurname'];
      $MM_fldUserAuthorization = "";
      $MM_redirectLoginSuccess = "member_update.php";
      $MM_redirectLoginFailed = "login.php";
      $MM_redirecttoReferrer = false;
      mysql_select_db($database_panto, $panto);
      $LoginRS__query=sprintf("SELECT firstname, surname FROM web_access WHERE firstname=%s AND surname=%s",
        GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
      $LoginRS = mysql_query($LoginRS__query, $panto) or die(mysql_error());
      $loginFoundUser = mysql_num_rows($LoginRS);
      if ($loginFoundUser) {
         $loginStrGroup = "";
        if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
        //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 );
    ?>
    Firstly, the text highlighted in red above appears to be setting the session variable that I require. Is This correct?
    If so, what is the code that I need to place in page 2 to use that session variable? or
    Do I need to do something else on page 1 to properly assign the session variable?
    Would really appreciate your expertise
    Mark

    It looks as though you've set the columns incorrectly in the User Authentication server behavior. This is the SQL query that checks the user's credentials:
      $LoginRS__query=sprintf("SELECT firstname, surname FROM web_access WHERE firstname=%s AND surname=%s",
        GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
    You're looking for firstname and surname, whereas you should be looking for the user's login name and password.
    $_SESSION['MM_Username'] is a session variable that stores the user's login name. To use it in a subsequent page, all that's needed is for the page to begin with session_start(). You can then echo the value to display it.
    If you want to display the person's real name, you need to create a recordset in the second page using $_SESSION['MM_Username'] to find the firstname and surname. Alternatively, you can edit the existing code like this (I've copied only part of it):
      $LoginRS__query=sprintf("SELECT firstname, surname FROM web_access WHERE firstname=%s AND password=%s",
        GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
      $LoginRS = mysql_query($LoginRS__query, $panto) or die(mysql_error());
      $loginFoundUser = mysql_num_rows($LoginRS);
      if ($loginFoundUser) {
         $loginStrGroup = "";
        $row = mysql_fetch_assoc($LoginRS);
         $_SESSION['full_name'] = $row['firstname'] . ' ' . $row['surname'];
        if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
        //declare two session variables and assign them
       $_SESSION['MM_Username'] = $loginUsername;
        $_SESSION['MM_UserGroup'] = $loginStrGroup;
    You can then use $_SESSION['full_name'] in a subsequent page that begins with session_start().

  • 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/

  • 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!';
    ?>

  • 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]
    >

  • Session variables in jsp,php

    Dear friends,
    is there any way tht i can pass the session variables set in a jsp file to a php file. Is there any way to do this apart from setting cookies?
    plz help!!
    bussa

    You can create POST or GET request.

  • 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']; ?>

  • 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>

  • Passing Session Variable from PHP to Applet

    I'm trying to pass a session variable from a PHP script to a third party applet. The applet needs to accept the variable as a string into a parameter. I think the htnl has to be dynamically created to turn the session variable into a string for the parameter value. Any suggestions ?

    This is really a PHP question. You might get better results on a PHP forum.

  • Retrieving a session variable from a php script and putting it in an applet

    I have a chat applet and i'm trying to have a session variable in one my php scripts be setted onto the user area of my chat. Would it start out by doing this?
    <object codetype="application/java"
    code = "ClientApplet.class"
    width = "300"
    height = "400"
    classid = "the name of the session variable">
    </object>

    No.
    Use the parameter tags.

Maybe you are looking for