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/

Similar Messages

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

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

  • Session Variables to control Datasource used by iBots

    Hello everyone,
    i'd like to know whether it is possible to control the session which is used by iBots.
    What i want to achieve is, that i can start an iBot within a certain session with given parameters, based on session variables.
    I have one SessionVariable "sDB" which can be set to =1 or =2. This is controled via the URL used to start OBIEE.
    Now i want to control my ibots by forcing them to start with sDB=1 or sDB=2 etc.
    Does anybody know a solution. Any hint might help aswell.
    Thanks!

    Thank you David for the response. As you guessed, I'm fairly new with session variables. What I'm looking for is as follows-
    On my Architecture website, I have an html form where clients would enter their design preferences and Submit. The website then sends an email to the client with the details they had entered; for confirmation. This had worked properly with form variables as the email is sent right after the form is filled.
    However, now I have added a License agreement page and a second form with other design details, which has to be filled in before the client's email is sent. So, I've set the Page1 form variables as session variables to carry over to the 4th page where it is sent as email. I am able to retrieve the session variables on the fourth page, but what I require is the correct syntax for using it in the subject field and the message body of the email, so that the clients get them in their email.
    I had earlier used the following php code for sending emails using form variables-
        $to="From: $email";
        $subject="$name, Thank you for visiting our website.";
        $from="[email protected]";
        $msg="Your Reg. details-\r\n\n$name\r\n$address\r\n\nPhone No: $phone \r\nE mail: $email \r\n\nMessage:\n$message";
        $fla=mail($to,$subject,$msg,$from);
    ; where the form variables are- $name, $address, $phone, $email, $message
    I have now set them as session variables-
    <?php
    session_start();
    $_SESSION['name'] = $name;
    $_SESSION['address'] = $address;
    $_SESSION['phone'] = $phone;
    $_SESSION['email'] = $email;
    $_SESSION['message'] = $message;
    ?>
    ; and I'm being able to retrieve them on the 4th subsequent page. As mentioned, what I am looking for is the correct syntax to use this data in a php email code.
    I will be very grateful if you could provide me with a sample php email code for sending an email with session variables in the 'from', 'to', 'subject' and 'message' fields.

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

  • 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

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

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

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

  • Session variable not storing in custom trigger

    I have a custom trigger in which I want to store a session variable , so i can use the value in the insert transaction which happens after. But for some reason the session variable is not stored, resulting in the data not being stored.
    any clues would help.
    rudi
    here are the relevant code:
    //start Trigger_Custom_Subject_Mentor trigger
    function Trigger_Custom_Subject_Mentor(&$tNG) {
    //Check subject exists
    @session_start();
    $_SESSION['sb_id'] = $subject_id;
    //end Trigger_Custom_Subject_Mentor trigger
    // Make an insert transaction instance
    $ins_share = new tNG_insert($conn_smart);
    $tNGs->addTransaction($ins_share);
    // Register triggers
    $ins_share->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
    $ins_share->registerTrigger("END", "Trigger_Redirect", 90);
    // Add columns
    $ins_share->setTable("`share`");
    $ins_share->addColumn("share_item", "NUMERIC_TYPE", "POST", "share_item");
    $ins_share->addColumn("share_subject", "NUMERIC_TYPE", "SESSION", "sb_id");
    $ins_share->setPrimaryKey("share_id", "NUMERIC_TYPE");
    // Register triggers
    $ins_share->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
    $ins_share->registerTrigger("BEFORE", "Trigger_Custom_Subject_Mentor", 50);
    $ins_share->registerTrigger("END", "Trigger_Default_Redirect", 99, "share.php?item_id={share_item}");

    hi User,
    1) Pull a dummy column in Fx use the Session variable --->(Variable -->session )
    2) Next, goto narrative view in Narrative view section use @1
    3) If u want you can hide the column that we created in criteria section

  • Unable to filter a recordset using a session  variable

    I have a volunteer application page and when the volunteer presses <Submit> their info is saved in a MySQl db table and a session variable is created containing the primary key of their record in the table, control is then passed to a "success page". The success page can access the session variable (I proved this by displaying the session variable on the success page) so my next step was to create a recordset in the success page with a filter using the session variable to select the appropriate row in the table, allowing me to display to the volunteer the info they submitted.
    I set up a test success page which displays the session variable and one field of the volunteer info. When I test this I see the session variable displayed but the corresponding volunteer info field from the recordset is not displayed.
    The volunteer application page is here www.hollisterairshow.com/volunteerapp.php and the successpage is here www.hollisterairshow.com/thanksvol.php
    The code that creates the session variable in the volunteer application page is shown below
    $_SESSION['volunteer_id'] = mysql_insert_id();
    The code to display the session variable in the success page is shown below
    <?php  echo $_SESSION['volunteer_id']; ?>
    The code to display the volunteer info is shown below
    <h1> Thank You <?php echo $row_rsVolunteerApp['firstname']; ?>!! </h1>
    The recordset definition is shown below
    The success page test result is shown below, as you can see the volunteer's first name is not displayed immediately after the "Thank you" message but the session variable holding the correct primary key (41) is shown correctly.
    Does anyone have an idea of what I'm doing wrong?
    Thanks
    Tony

    Where did you put session_start()? It needs to be before the variable is accessed. It's obviously before the line that displays the value in your page, but is it before the SQL query is generated?
    Also, have you checked in phpMyAdmin to see whether volunteernumber 41 has any values in the database?

Maybe you are looking for

  • Save ALV report output as excel file in background

    Hi all, As the no. of records is huge and the running time is long, I'd like to modify my program to be able to run in background mode with excel as output.. Is there any method to generate the result list in ALV format and save it as an excel file w

  • Package com.sun.deploy.util does not exist, failed to import com.sun.deploy.util.VersionID;

    Java 1.6 JRE contains deploy.jar, which provides the VersionID class. However, Java 1.8u5 does not have it anymore. I cannot find any log w.r.t the change. Can anyone please point out whether the absence is deliberate or just an accident? If delibera

  • How to access updated receipts in rcv_shipment_headers using triigger

    Hi, I am working on PUT Away Label Report : The process is as follows: When receipt is saved , a trigger will fire on RCV_SHIPMENT_HEADERS and in trigger a package will be called which in turn will submit the report for the receipt that is newly crea

  • Details Designer for Organisational Structure

    Hi, I see that the position hierarchy detail's designer comes with a "Structure" tab as default. I am trying to get this to appear for the Organisational Structure but having no luck. Can this be achieved within the console? Many thanks

  • My desktop keep disappearing,

    there is nothing there but the background picture. I have to shut down and reboot to get it back. I lose everything I was working on. This happens if u leave it for a short period and come back you have a blank screen nothing works.