Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Add session_start to the top of the script. This one is still wrong: $_SESSION("Login")=$Prename;, as you cannot assign to a result of a function call (remember, $_SESSION("login") is trying to map $_SESSION to a callable function which will fail). Those must be changed to square braces.

    Also, best to make sure your variables exist:
    PHP Code:
    $Prename=isset($_POST['Prename']) ? trim($_POST['Prename']) : '';
    $Surname=isset($_POST['Surname']) ? trim($_POST['Surname']) : ''
    If the script is accessed without these two post variables, they will default to nothing without triggering a notice.

    Watch the use of the operators as well. These are deceiving (though correct here as well), since both exist in PHP:
    PHP Code:
    $Prename=="firstname1" && $Surname=="lastname1" or $Prename=="firstname2" && 
    Notice your use of && and OR. PHP has all four ops for this: '&&' > '||' > '=' > 'AND' > 'OR', if you can read that ok. This works no problem since all levels of and override that of OR. This can be found on the precedence list here: http://php.ca/manual/en/language.ope...precedence.php

    Notice if you switched things up:
    PHP Code:
    $Prename == "firstname1" AND $Surname == "lastname1" || $Prename == "firstname2"... 
    The evaluation changes from logical: if ((prename AND surname) OR (prename.....) to: if (prename AND (surname OR prename) AND....), which is definitely not what you want.
    Last edited by Fou-Lu; 04-13-2011 at 05:01 PM. Reason: OP modified to remove sensitive, reflected here
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  2. #17
    New Coder
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You omitted the session_start() function so your variables are getting lost during the page refresh. Also your assignment operators ie $Surname==""; should only have one =.

  3. #18
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by munkeyboy View Post
    You omitted the session_start() function so your variables are getting lost during the page refresh. Also your assignment operators ie $Surname==""; should only have one =.
    Yep, good catch I completely missed that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  4. #19
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I do have the session_start() on the first line of my page, It just says<?php session_start(); ?> is that enough?

  5. #20
    New Coder
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Yes that is sufficient, however that wasn't in the code you posted so as far as we could tell it wasn't there. Once you fix the double equals (==) in your assignment operators then your code should work.

    Edit:
    Assignment Operators and Comparison Operators

  6. #21
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I did what you said, but now it thinks $_SESSION['LoginTester']==True, (which I haven't even set yet!) when I first enter the page. The updated script is:

    PHP Code:
    <?php
    $Prename
    =$_POST['Prename'];
    $Surname=$_POST['Surname'];

    if (
    $_SESSION['LoginTester']==True)
      {
      echo 
    "Hello, " $_SESSION['Login'];
      }
    else
      {
      if (
    $Surname=="Surname")
        {
        
    $Surname="";
        }

      if (
    $Prename=="Prename")
        {
        
    $Prename="";
        }

      if (
    $Prename <> "" && $Surname <> "")
        {
        if (
    //the names)
          
    {
          
    $_SESSION["LoginTester"]=True;
          
    $_SESSION["Login"]=$Prename " " $Surname;
          }
        else
          {
          echo 
    "<u>Login</u><br>You are not a registered user";
          }
        }
      else
        {
        if (
    $Prename=="//another name" && $Surname=="")
          {
          
    $_SESSION["LoginTester"]=True;
          
    $_SESSION["Login"]=$Prename;
          }
        else
          {
          echo 
    "<u>Login</u><br>Please login<br><form action='Stories.php' method='post'><input type='text' value='Prename' name='Prename'><br><input type='text' value='Surname' name='Surname'><br><input type='Submit' value='Submit'></form>";
          }
        }
      }
    ?>
    It basically doesn't give me a chance to imput my login and just runs echo "Hello, " . $_SESSION['Login'] but the Session Variable 'login' doesn't exist so it comes up blank

  7. #22
    New Coder
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Try closing your browser then reopening it before trying to access the form again. It's very possible that your session data is being saved and without having a logout script in place the easiest way to log out is to close and re-open the browser. If that resolves the issue then you will need to build a method of logging out of the session. The session_destroy function would be a good place to start.

  8. #23
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    considering a logout script, is there any way I could get a button or hyperlink to run the session_destroy function.

  9. #24
    New Coder
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    0
    Thanked 3 Times in 3 Posts
    There are several ways you could go about it, the simplest method would be to have a single (separate) page that only had the session_destroy function in it, then by linking to that page you would be able to logout.

  10. #25
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    wouldn't that only work with a button though?


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •