PHP Login System with Admin Features

Would you like to react to this message? Create an account in a few clicks or log in to continue.
PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


2 posters

    Session variables

    mbrad
    mbrad


    Number of posts : 42
    Registration date : 2009-02-19

    Session variables Empty Session variables

    Post  mbrad Tue Mar 30, 2010 5:26 pm

    Thanks for taking the time to read my question.

    I've got this code working fairly well for what I need. I'm kind of new to php (learn in spurts) and I need to figure out how I can pass the name of a file that I'm saving to the server from one page to another.

    I've created a variable on the sessions.php page called $snap

    In my process.php page where I'm allowing the user to post a file to the server, I'm doing
    Code:
    $_SESSION['snap'] = "TEST";
    just for now, but it's not showing up on the new page that gets loaded after the file is copied.

    The form to copy the file is page1.php, and the next form that I want the user to use is on page2.php. I can't get the word "TEST" to show up on page2.php

    On both pages I've included sessions.php, and on page2.php I have
    Code:
    <?php $session->snap ?>
    I thought that should return "TEST".

    Any help would be great.

    Thanks,

    Brad
    Linchpin311
    Linchpin311


    Number of posts : 220
    Age : 38
    Localisation : Long Island
    Registration date : 2007-05-14

    Session variables Empty Re: Session variables

    Post  Linchpin311 Tue Mar 30, 2010 11:11 pm

    well first off, the session variable in php is a global variable (like $_POST and $_GET). in short, this means you dont need to create a new variable in session.php to use it.

    when you call <?php $session->snap ?> php is looking for a function (or method) inside the session class, but since it doesnt exist, nothing is displayed. in other words, try saying <?php echo $_SESSION['snap'] ?> instead.

    Just remember session variables exist as long as your session exists (as opposed to regular variables that expire once the script is over) so once you are done using your session variable you may want to call unset($_SESSION['snap']); to delete the variable.

    lemme know if this works for you!
    mbrad
    mbrad


    Number of posts : 42
    Registration date : 2009-02-19

    Session variables Empty Re: Session variables

    Post  mbrad Wed Mar 31, 2010 11:10 am

    I gave it a shot and no luck.

    Here is the code I have.

    This is in process.php
    Code:
     /*snap to db load*/
      function procUpSnap() {
      global $session, $form;
       if ((($_FILES["file"]["type"] == "image/gif")
          || ($_FILES["file"]["type"] == "image/jpeg")
          || ($_FILES["file"]["type"] == "image/jpg")
          || ($_FILES["file"]["type"] == "image/png"))
          && ($_FILES["file"]["size"] < 40000))
          {
          if ($_FILES["file"]["error"] > 0)
             {
             echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
             }
          else
             {
             echo "Upload: " . $_FILES["file"]["name"] . "<br />";
             echo "Type: " . $_FILES["file"]["type"] . "<br />";
             echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
             echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
          
             if (file_exists("Upload/" . $_FILES["file"]["name"]))
                {
                echo $_FILES["file"]["name"] . " already exists. ";
                  }
             else
                  {
                  move_uploaded_file($_FILES["file"]["tmp_name"],"Upload/" . $_FILES["file"]["name"]);
                  /*echo "Stored in: " . "Upload/" . $_FILES["file"]["name"];*/
                $_SESSION['snap'] = "testing";
                echo "<script>alert('File upload successful');</script>";
                header("Location: PlayerEntry.php");
                  }
             }
            }
       else
          {
          echo "Invalid file";
          }
       }


    This is in page2.php
    Code:
    <?php
    include("include/session.php");
    ?>
    </head>
    <body>
       <div id="form_container">
       
          <h1><a>TNFHL Player Information Entry Form</a></h1>
          <form id="form_211520" class="appnitro"  method="post" action="process.php">
          <div class="form_description">
             <h2>TNFHL Player Information Entry Form</h2>
             <h3>Step 2: Enter Information</h3>
                <p>Please ensure that all information is correct, spelling, letter case and so on, before submitting the information. Thank you TNFHL</p>
    //This is the part that is not showing up.           
    <p><?php echo $session->snap ?> has been saved to the server</p>            </div>

    I'm expecing page2.php to have

    testing has been saved to the server
    at the top. All I get is
    has been saved to the server

    Not sure what I'm doing wrong.

    Brad
    Linchpin311
    Linchpin311


    Number of posts : 220
    Age : 38
    Localisation : Long Island
    Registration date : 2007-05-14

    Session variables Empty Re: Session variables

    Post  Linchpin311 Wed Mar 31, 2010 11:50 am

    well as far as i can tell, the file is being successfully uploaded to the server. can you just confirm that the new file is indeed being created on the server? so it looks like the problem is on page2.php. now if you say that you tried <?php echo $_SESSION['snap']; ?> in place of what you have now and it isnt working i am curious what is in the session array.

    for the time being, comment out <p><?php echo $session->snap ?> has been saved to the server</p> and under that line add a new line and put <pre><?php print_r($_SESSION) ?></pre>. that should (as long as the file from page1.php is being successfully created) display all the values inside the $_SESSION array. lemme know what that returns.
    mbrad
    mbrad


    Number of posts : 42
    Registration date : 2009-02-19

    Session variables Empty Re: Session variables

    Post  mbrad Wed Mar 31, 2010 12:03 pm

    AAhhhhh I have to get my eyes checked....

    I didn't type in what you told me to type in correctly, then I changed it back.

    I now typed in what you told me to type in CORRECTLY, and it works.

    Sorry.

    So I don't have to create variables in the session.php page, I just do what I've done here and that's good enough? Then I just need to unset them when done.

    Thanks for the help.

    Brad
    Linchpin311
    Linchpin311


    Number of posts : 220
    Age : 38
    Localisation : Long Island
    Registration date : 2007-05-14

    Session variables Empty Re: Session variables

    Post  Linchpin311 Wed Mar 31, 2010 12:30 pm

    mbrad wrote:So I don't have to create variables in the session.php page, I just do what I've done here and that's good enough? Then I just need to unset them when done.
    to make use of the $_SESSION variable, no you dont. like i said, $_SESSION is a global variable (like $_GET $_POST or $_FILE) so you can use them on any page where a session has been opened. in our particular script any page where we include session.php now has a session opened and can make use of the $_SESSION variable. and just remember $_SESSION variables stay alive as long as the session is alive so its good practice to unset the variable when you are done with it.

    glad to see this is working for you now!

    Sponsored content


    Session variables Empty Re: Session variables

    Post  Sponsored content


      Current date/time is Fri May 17, 2024 7:40 am