473,383 Members | 1,725 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,383 software developers and data experts.

syntax error, unexpected ':' in /home/allummfa/public_html/auth.php on line 11

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 code - header(‘WWW-Authenticate: Basic realm=”secret section”’);
Then when I remove the colon, I get a new error - syntax error, unexpected T_STRING in /home/allummfa/public_html/auth.php on line 11.
This code is supposed to tell the web server to send the headers to the client's browser to prompt for a username and password when the user tries to access my restricted web page. Here's my complete coding 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
10 2295
stepterr
157 100+
I've found that most of the time the syntax errors are actually caused by the line before the one it reports.

In your case I noticed that the line before has "nameif(". If that is how it actually is in your code I would start there. It looks like the word "name" should be part of the comment above.
Dec 15 '07 #2
I've found that most of the time the syntax errors are actually caused by the line before the one it reports.

In your case I noticed that the line before has "nameif(". If that is how it actually is in your code I would start there. It looks like the word "name" should be part of the comment above.

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 i'm still getting 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 #3
stepterr
157 100+
Try changing your if statement to this.

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

As soon as I did that I was prompted with the pop up box. Let me know how that works for you.
Dec 16 '07 #4
Try changing your if statement to this.

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

As soon as I did that I was prompted with the pop up box. Let me know how that works for you.
Lovely it works this time. The difference between your code and mine is that you use the echo command to display the authorisation comment, whereas I place that comment within quotes....looks like these error messages sometimes are misleading?......anyway, I got my code from a book retailing in a store.....mmmm.
Looks like i'l be sticking to this site for php support...thanks again.
Now i'l work on the rest of my code...
Dec 17 '07 #5
stepterr
157 100+
....looks like these error messages sometimes are misleading?......
Yeah, unfortunately sometimes that is the case, but at least it does point you in the general area that you need to start looking. Glad that worked for you!
Dec 17 '07 #6
Yeah, unfortunately sometimes that is the case, but at least it does point you in the general area that you need to start looking. Glad that worked for you!
I've started working on the remainder of my code which involves making an sql query to validate the user's username and password.

I get the error "Parse error: syntax error, unexpected T_STRING in /home/allummfa/public_html/auth.php on line 24".

I've gone over the code carefully (which incidentally I got from a php book) and perhaps the SELECT command is not quite right. I had created another file called Vars.inc which contains the database table info and other info needed by the mysql functions. With my php book I should'nt have to be seeking help from forums but there you go. I figure once I get this project working ok the I should be ok with future projects. The vars.inc file has the code:

<?php
$host = "localhost";
$user = "my username";
$password = "mypassword";
$database = "UserAccount";

CREATE TABLE Valid_User (
user_name CHAR(25) NOT NULL,
password CHAR(25) NOT NULL,
create_date DATE NOT NULL,
PRIMARY KEY(user_name));
?>

I'm not fully sure if the Vars.inc file should be saved as an .inc file as it is now or as a .php file.
This is the main block of code which you know of already:

<?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');
echo 'This page requires authentication!';
exit;
}

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;
echo 'Couldn’t connect to server.';
$db = mysql_select_db($database,$connection)or die;
echo '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;
echo 'Couldn’t execute query.';
$num = mysql_num_rows($result);
if ($num < 1)
{

echo 'The User Name or Password you entered is not valid.';
exit;

}
}
include(“imagegallery.inc”);

?>
Dec 18 '07 #7
stepterr
157 100+
I just edited the quotes a little and added a space before the word "AND". I was able to get the prompt to come up after changing it. See if this works for you also.
[PHP]
$sql = "SELECT user_name FROM Valid_User WHERE user_name = ‘$user_name’ AND password = md5(‘$user_password’)";[/PHP]
Dec 18 '07 #8
I just edited the quotes a little and added a space before the word "AND". I was able to get the prompt to come up after changing it. See if this works for you also.
[PHP]
$sql = "SELECT user_name FROM Valid_User WHERE user_name = ‘$user_name’ AND password = md5(‘$user_password’)";[/PHP]

Hi it works now, many thanks.
I see php can be tricky. I'm going to work on the sql database now......
Dec 19 '07 #9
stepterr
157 100+
You're welcome, glad it worked! I've found that making small tweeks to the lines surrounding a syntax error usually does the trick until you find out for sure which one is the problem. You might also want to try commenting out lines in order to help you narrow down the problem when it might not be straight forward, that usually helps me quite a bit when I'm stuck.
Dec 19 '07 #10
You're welcome, glad it worked! I've found that making small tweeks to the lines surrounding a syntax error usually does the trick until you find out for sure which one is the problem. You might also want to try commenting out lines in order to help you narrow down the problem when it might not be straight forward, that usually helps me quite a bit when I'm stuck.
ok thanks for the tip.
Dec 23 '07 #11

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

Similar topics

1
by: Matt Schroeder | last post by:
I'm a newbie and I can't figure out what this error means: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/easilyta/public_html/pub/user.php on line 190....
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: '\'...
2
by: BlackKite | last post by:
I have this script I wrote up as a php backend. But its throwing some errors i dont quite understand. Hope someone can help me fix this. Please Error: Line 52: ftp_fput($connection, $bandle,...
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...
5
by: goodguyjam | last post by:
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 *...
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...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.