...

View Full Version : What do the different bits of this code do?



jake66
08-24-2011, 01:54 PM
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:


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

djm0219
08-24-2011, 02:30 PM
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.



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

jake66
08-24-2011, 02:43 PM
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

djm0219
08-24-2011, 03:11 PM
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.

jake66
08-24-2011, 08:50 PM
Ahh, my fault, sorry. It works perfectly, thanks so much :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum