473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

syntax error, unexpected T_ELSE in /home/allummfa/public_html/auth.php on line 10

Hi I'm trying to apply user authentication with HTTP on my site but i get the above error. Can anyone say whats wrong?? I cant figure it out. Here's my code below:

<?php
/* Program: Auth.php
* Desc: Program that prompts for a user name and
* password from the user using HTTP authentication.
* The program then tests whether the user
* name and password match a user name and password
* pair stored in a MySQL database.
*/
//Testing whether the user has been prompted for a user nameif(!isset($_SERVER[‘PHP_AUTH_USER’])){header(‘WWW-Authenticate: Basic realm=”secret section”’);header(‘HTTP/1.0 401 Unauthorized’);exit(“This page requires authentication!”);}
// Testing the user name and password entered by the user
else{
include(“Vars.inc”);
$user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
$user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
$connection = mysql_connect($host,$user,$password)or die (“Couldn’t connect to server.”);$db = mysql_select_db($database,$connection)or die (“Couldn’t select database.”);$sql = “SELECT user_name FROM Valid_User WHERE user_name = ‘$user_name’AND password = md5(‘$user_password’)”;$result = mysql_query($sql)or die(“Couldn’t execute query.”);$num = mysql_num_rows($result);if ($num < 1) // user name/password not found
{
exit(“The User Name or Password you entered is not valid.<br>”);

}
}
//web page content.
include(“imagegallery.inc”);
?>
Dec 13 '07 #1
5 2475
helraizer1
118 100+
In your code, your if statement is part of the comment. That is why it does not work.

Sam
Dec 13 '07 #2
In your code, your if statement is part of the comment. That is why it does not work.

Sam
thanks helraizer1, i'l give this a go...i should have spotted this :(
Dec 14 '07 #3
In your code, your if statement is part of the comment. That is why it does not work.

Sam

Hi
Thanks for this.
I decided to remove most comments and re-arrange the line with the "if" script so that it all flows properly now.
But now I get the error "Parse error: syntax error, unexpected ':' in /home/allummfa/public_html/auth.php on line 12".

The only line in my code that uses the ":" is this line - header(‘WWW-Authenticate: Basic realm=”Image gallery”’);
I did some research in google and found that this line is correctly written, including the ":". So this is confusing as I consistently get this error. All I want to do is get the first part of my coding to work which is to display the pop up window that prompts a user to enter their username and password and then i'l worry about the rest of the coding afterwards. I call the php script Auth.php and I have directed a link in my HTML code to this page, so that once a user clicks on the link, Auth.php should execute and the login prompt should display, at least thats how I believe it should work.
Maybe if you test my php script here and see if it works for you......help.
The re-arranged code is below:

<?php
/* Program: Auth.php
* Desc: Program that prompts for a user name and
* password from the user using HTTP authentication.
* The program then tests whether the user
* name and password match a user name and password
* pair stored in a MySQL database.
*/

if(!isset($_SERVER[‘PHP_AUTH_USER’]))
{
header(‘WWW-Authenticate: Basic realm=”Image gallery”’);
header(‘HTTP/1.0 401 Unauthorized’);
exit(“This page requires authentication!”);}

else{
include(“Vars.inc”);
$user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
$user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
$connection = mysql_connect($host,$user,$password)or die (“Couldn’t connect to server.”);
$db = mysql_select_db($database,$connection)or die (“Couldn’t select database.”);
$sql = “SELECT user_name FROM Valid_User WHERE user_name = ‘$user_name’AND password = md5(‘$user_password’)”;
$result = mysql_query($sql)or die(“Couldn’t execute query.”);
$num = mysql_num_rows($result);
if ($num < 1)
{
exit(“The User Name or Password you entered is not valid.<br>”);

}
}
include(“imagegallery.inc”);
?>
Dec 16 '07 #4
helraizer1
118 100+
Hi
Thanks for this.
I decided to remove most comments and re-arrange the line with the "if" script so that it all flows properly now.
But now I get the error "Parse error: syntax error, unexpected ':' in /home/allummfa/public_html/auth.php on line 12".

The only line in my code that uses the ":" is this line - header(‘WWW-Authenticate: Basic realm=”Image gallery”’);
I did some research in google and found that this line is correctly written, including the ":". So this is confusing as I consistently get this error. All I want to do is get the first part of my coding to work which is to display the pop up window that prompts a user to enter their username and password and then i'l worry about the rest of the coding afterwards. I call the php script Auth.php and I have directed a link in my HTML code to this page, so that once a user clicks on the link, Auth.php should execute and the login prompt should display, at least thats how I believe it should work.
Maybe if you test my php script here and see if it works for you......help.
The re-arranged code is below:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /* Program: Auth.php
  3. * Desc:    Program that prompts for a user name and 
  4. *          password from the user using HTTP authentication.
  5. *          The program then tests whether the user
  6. *          name and password match a user name and password 
  7. *          pair stored in a MySQL database.
  8. */
  9.  
  10. if(!isset($_SERVER[‘PHP_AUTH_USER’]))
  11. {
  12. header(‘WWW-Authenticate: Basic realm=”Image gallery”’);
  13. header(‘HTTP/1.0 401 Unauthorized’);
  14. exit(“This page requires authentication!”);}
  15.  
  16. else{
  17. include(“Vars.inc”);
  18. $user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
  19. $user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
  20. $connection = mysql_connect($host,$user,$password)or die (“Couldn’t connect to server.”);
  21. $db = mysql_select_db($database,$connection)or die (“Couldn’t select database.”);
  22. $sql = “SELECT user_name FROM Valid_User WHERE user_name = ‘$user_name’AND password = md5(‘$user_password’)”;
  23. $result = mysql_query($sql)or die(“Couldn’t execute query.”);
  24. $num = mysql_num_rows($result);
  25. if ($num < 1)  
  26. {
  27. exit(“The User Name or Password you entered is not valid.<br>”);
  28.  
  29. }
  30. }
  31. include(“imagegallery.inc”);
  32. ?>
Hi Goodguyjam,

I'm not sure how/why but you're using a different type of " and ' (double quotes and quotes). So it's technically not a string.

use this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /* Program: Auth.php
  3. * Desc: Program that prompts for a user name and
  4. * password from the user using HTTP authentication.
  5. * The program then tests whether the user
  6. * name and password match a user name and password
  7. * pair stored in a MySQL database.
  8. */
  9.  
  10. if(!isset($_SERVER[‘PHP_AUTH_USER’]))
  11. {
  12. header("WWW-Authenticate: Basic realm=”Image gallery”");
  13. header("HTTP/1.0 401 Unauthorized");
  14. exit("This page requires authentication!");}
  15.  
  16. else{
  17. include(“Vars.inc”);
  18. $user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
  19. $user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
  20. $connection = mysql_connect($host,$user,$password)or die ("Couldn’t connect to server.");
  21. $db = mysql_select_db($database,$connection)or die ("Couldn’t select database.");
  22. $sql = "SELECT user_name FROM Valid_User WHERE user_name = ‘$user_name’AND password = md5(‘$user_password’)";
  23. $result = mysql_query($sql)or die("Couldn’t execute query.");
  24. $num = mysql_num_rows($result);
  25. if ($num < 1)
  26. {
  27. exit("The User Name or Password you entered is not valid.<br>");
  28.  
  29. }
  30. }
  31. include("imagegallery.inc");
  32. ?>
Sam
Dec 18 '07 #5
Hi Goodguyjam,

I'm not sure how/why but you're using a different type of " and ' (double quotes and quotes). So it's technically not a string.

use this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /* Program: Auth.php
  3. * Desc: Program that prompts for a user name and
  4. * password from the user using HTTP authentication.
  5. * The program then tests whether the user
  6. * name and password match a user name and password
  7. * pair stored in a MySQL database.
  8. */
  9.  
  10. if(!isset($_SERVER[‘PHP_AUTH_USER’]))
  11. {
  12. header("WWW-Authenticate: Basic realm=”Image gallery”");
  13. header("HTTP/1.0 401 Unauthorized");
  14. exit("This page requires authentication!");}
  15.  
  16. else{
  17. include(“Vars.inc”);
  18. $user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
  19. $user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
  20. $connection = mysql_connect($host,$user,$password)or die ("Couldn’t connect to server.");
  21. $db = mysql_select_db($database,$connection)or die ("Couldn’t select database.");
  22. $sql = "SELECT user_name FROM Valid_User WHERE user_name = ‘$user_name’AND password = md5(‘$user_password’)";
  23. $result = mysql_query($sql)or die("Couldn’t execute query.");
  24. $num = mysql_num_rows($result);
  25. if ($num < 1)
  26. {
  27. exit("The User Name or Password you entered is not valid.<br>");
  28.  
  29. }
  30. }
  31. include("imagegallery.inc");
  32. ?>
Sam
Hi and thanks for your response. I actually got this working already from advice from another member. I basically re-entered the quotation marks as I had copied the code from a php book i'm learning from and it appears that what was copied was not been read properly on the server. But stand by I may have more questions :)
Dec 19 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Hong | last post by:
Hi, I am trying to create a switch but I do not know why I am geting an error message, can someone tell me what is wrong, Error Message; Warning: Unexpected character in input: '\'...
3
by: Marten van Urk | last post by:
I got the following error in my page Parse error: parse error, unexpected T_ELSE in line 25 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Club</title>...
1
by: fredie108 | last post by:
I've installed a link request script and when testing the link request form I get this: Parse error: syntax error, unexpected '@' in /home/mybusiness/public_html/output.php on line 91 I then...
10
by: goodguyjam | last post by:
Hi again. I now get the above error with the exact same code as in my previous question. All I did was to rearrange the lines...no code changes...help! To assist you experts, line 11 contains this...
6
by: goodguyjam | last post by:
Hi all, I'm having trouble with mysql. I've just finished my php coding for HTTP authentication and with some help am now getting a login window pop up whenever I click on a link on my website...
1
by: sheenrose | last post by:
<? $uname = $_REQUEST; $pass = $_REQUEST; /*Connecting, selecting database */ $LogStatus = 0; $link = mysql_connect("localhost","root","kushal") or die();
9
by: exoduses | last post by:
Hi, I was wondering if anyone could help me. This site is for college, and I have everything else working, except for this PHP thingy. This is the error message I get: Parse error: syntax error,...
25
by: URmusicandvideo | last post by:
I have just finshed my first php code and posted it online and I am getting a Parse error: syntax error, unexpected T_VARIABLE in /home/hydeands/public_html/phpmail.php on line 45 But when I look...
14
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.