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.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    What do the different bits of this code do?

    Hello,

    I am doing a user authentication script, and I want it to only check the username not the ip address for authorisation. The code I have is this:

    PHP Code:
    session_start(); 
    $newip $_SERVER['REMOTE_ADDR']; 
    if (!isset(
    $_SESSION['username']) ¦¦  
    empty($_SESSION['username']) ¦¦ $newip!= $_SESSION['ip']) { 
     include 
    "logout.php"

    First of all, this code on its own has syntax errors that I cannot find. Any light on this would be great.

    Secondly, I want to change this code so it only checks the username and not the ip address. How do I do this. Part of my confusion was the strange ¦ symbol????

    Thanks Jake

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,302
    Thanks
    4
    Thanked 204 Times in 201 Posts
    The errors are being caused by the split vertical bars. Changing them to sold vertical bars will solve the syntax error. To not check the address simply remove its OR condition from the if statement.

    PHP Code:
    session_start();
    if (!isset(
    $_SESSION['username']) || empty($_SESSION['username'])) {
     include 
    "logout.php";

    Dave .... HostMonster for all of your hosting needs

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks so much for your reply.
    I think we are on the right tracks here, but I am still get a 'Unexpected T_STRING error' on the second line. What does this mean and how can I fix it?

    Thanks Jake

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,302
    Thanks
    4
    Thanked 204 Times in 201 Posts
    I'm positive that if you copied what I posted you will not get an error from those 4 lines alone. If that is part of a larger program post it please. It is quite likely the error is not at all related to the small portion I posted.
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    jake66 (08-24-2011)

  • #5
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Ahh, my fault, sorry. It works perfectly, thanks so much


  •  

    Posting Permissions

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