admin if statement

This is an archive of the phpBB 2.0.x support forum. Support for phpBB2 has now ended.
Forum rules
Following phpBB2's EoL, this forum is now archived for reference purposes only.
Please see the following announcement for more information: viewtopic.php?f=14&t=1385785
Locked
nad_
Registered User
Posts: 6
Joined: Tue Mar 22, 2005 6:08 pm

admin if statement

Post by nad_ »

I am implementing PHPBB2 auth system into a admin only area on my site. e.g, there is a member bar which I have created and if the logged in user is a admin, they can view the admin links. however, for the site acp, i use this code:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = "c:\program files\webserver\www\phpbb2\";
include('http://localhost/phpbb2/extension.inc');
include('http://localhost/phpbb2/phpbb2/common.php');
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_VIEWONLINE);
init_userprefs($userdata);
//
// End session management
//
if( $userdata['user_level'] == ADMIN )
{
//display body
all stuff for admin here
}
else
{
echo "Access denied! his area is only for admins!";
}
?>
however it says i have an errror on the if statement (where is checks if the user level is admin. anyone got any ideas?
thanks in advance

nad
User avatar
Marshalrusty
Project Manager
Project Manager
Posts: 29294
Joined: Mon Nov 22, 2004 10:45 pm
Location: New York City
Name: Yuriy Rusko
Contact:

Post by Marshalrusty »

You also have a typo.

Code: Select all

echo "Access denied! his area is only for admins!"; 
should be

Code: Select all

echo "Access denied! This area is only for admins!"; 
Last edited by Marshalrusty on Wed Aug 17, 2005 7:06 pm, edited 1 time in total.
Have comments/praise/complaints/suggestions? Please feel free to PM me.

Need private help? Hire me for all your phpBB and web development needs
nad_
Registered User
Posts: 6
Joined: Tue Mar 22, 2005 6:08 pm

Post by nad_ »

hi, thanks for the reply however i keep on getting the same parse error:

Code: Select all

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\webserver\www\admin\memberbar.php on line 14
btw, i dint notice the typo, thanks :d

nad
User avatar
Marshalrusty
Project Manager
Project Manager
Posts: 29294
Joined: Mon Nov 22, 2004 10:45 pm
Location: New York City
Name: Yuriy Rusko
Contact:

Post by Marshalrusty »

Sorry about that. Can you include the entire code (or PM it to me) so I can see where you may be making the error. Also, the actual error would be very helpful.
Have comments/praise/complaints/suggestions? Please feel free to PM me.

Need private help? Hire me for all your phpBB and web development needs
gmex2006
Registered User
Posts: 463
Joined: Mon Jul 25, 2005 1:34 am

Post by gmex2006 »

Is it the code you have displayed above? If yes, I suggest you to change the code

Code: Select all

$phpbb_root_path = "c:\program files\webserver\www\phpbb2\"
to

Code: Select all

$phpbb_root_path = "c:\program files\webserver\www\phpbb2"
and also

Code: Select all

all stuff for admin here
to

Code: Select all

//all stuff for admin here
Last edited by gmex2006 on Wed Aug 17, 2005 7:14 pm, edited 1 time in total.
gmex2006
Registered User
Posts: 463
Joined: Mon Jul 25, 2005 1:34 am

Post by gmex2006 »

"Small things, can create big errors" - Arundathi Roy :wink:
nad_
Registered User
Posts: 6
Joined: Tue Mar 22, 2005 6:08 pm

Post by nad_ »

i just put the "admin stuff here" so it would cut down on the code. i tried removing the "\" from root path but it gave errors so i removed it. full code:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = "c:\program files\webserver\www\phpbb\";
include('c:\program files\webserver\www\phpbb\extension.inc');
include('c:\program files\webserver\www\phpbb\common.php');
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_VIEWONLINE);
init_userprefs($userdata);
//
// End session management
//
if ($userdata['user_level'] == ADMIN)
{
//display body
$forum_admin_link = ( $userdata['user_level'] == ADMIN ) ? '<a href="admin/index.' . $phpEx . '?sid=' . $userdata['session_id'] . '" target="_blank">' . $lang['Admin_panel'] . '</a><br />' : '';
$site_admin_link = ( $userdata['user_level'] == ADMIN ) ? '<a href="admin/index.' . $phpEx . '?sid=' . $userdata['session_id'] . '" target="_blank">Go to Site Administration Panel</a><br />' : '';
$username = '<b><a href=profile.php?mode=viewprofile&u=' .$userdata['user_id']. '> ' . $userdata['username'] . ' </a></b>';
$logout_link_code = 'login.'.$phpEx.'?logout=true&sid=' . $userdata['session_id'];
$logout_link = '<a href=' .$logout_link_code. '>Logout</a>';
if( $userdata['session_logged_in'] ) 
{ 
echo ("Welcome back $username! <br>
$forum_admin_link <br>
$site_admin_link <br>
$logout_link
");
} 
else 
{ 
?>
<form action=login.php method=post>
      <fieldset style="width:50%;text-align:left;padding:10px">
      <legend style="color:black;font-weight:bold">Please login</legend><br />
Welcome <b>Guest</b>!<br />Please Login below or <a href=register.php>register</a>.
<table>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td><br />
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td><br />
</tr>
<tr>
<td><input type="submit" value="Login!" name="login"></td>
<td><input type="reset" value="Reset!" name="reset"></td>
</tr>
</table>
</fieldset>
</form>
<?php
}
}
?>
and i keep getting this error:

Code: Select all

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\webserver\www\admin\memberbar.php on line 14
btw, thank you for your support guys :D
geocator
Registered User
Posts: 16242
Joined: Fri Jan 09, 2004 11:56 pm
Location: On dry land
Contact:

Post by geocator »

You have several issues, you really need to learn proper php syntax if you want to create code. This line:

Code: Select all

$phpbb_root_path = "c:\program files\webserver\www\phpbb\";
begins your problems. if you use \ you must double them \\
gmex2006
Registered User
Posts: 463
Joined: Mon Jul 25, 2005 1:34 am

Post by gmex2006 »

geocator wrote: You have several issues, you really need to learn proper php syntax if you want to create code. This line:

Code: Select all

$phpbb_root_path = "c:\program files\webserver\www\phpbb\";
begins your problems. if you use \ you must double them \\


As geocator has said, you should either remove the \ or double it if you need to use it, otherwise the code is working.

Good Luck
_Maz_
Registered User
Posts: 7
Joined: Mon Aug 15, 2005 11:20 am

Post by _Maz_ »

mmm.. I might be wrong, but shouldnt the admin inside if statement be 'admin' ?

I mean if ($userdata['user_level'] == 'ADMIN')
nad_
Registered User
Posts: 6
Joined: Tue Mar 22, 2005 6:08 pm

Post by nad_ »

gmex2006 wrote:
geocator wrote:You have several issues, you really need to learn proper php syntax if you want to create code. This line:

Code: Select all

$phpbb_root_path = "c:\program files\webserver\www\phpbb\";
begins your problems. if you use \ you must double them \\


As geocator has said, you should either remove the \ or double it if you need to use it, otherwise the code is working.

Good Luck


i usually use the single \ and it works fine.. and maz, i tryed that, no luck either. ill try to doublt backslashes. i dont think its to do with them as it would have said unexpected ascii characters "\"
Locked

Return to “2.0.x Support Forum”