Currently using this to check the permissions of a user, If the user is logged in then it shows the file and lists the DIR. This works fine along with the login screen showing up if the user is not shown to be logged in.
I need it to be that if the product is not owned by the user (i.e. the permission is not level 3) then it will automatically link them to the brochure. I had a header setup to send the user but it does not function as I want it to.
Now what it does is loads the page but does not pass on the DIV (hence the name to check on the f12 debug to see if it had passed)
What am I missing?
p.s. the PHP logs show no errors
-- Update --
Gone through and commented out sections to see if the IF statement was attached to wrong thing, currently nothing still getting same problem
<?php
if (!securePage($_SERVER['PHP_SELF'])){die();}
$parts = parse_url($_SERVER["REQUEST_URI"]);
$page_name = basename($parts['path']);
//Links for logged in user
if(isUserLoggedIn()) {
//Links for permission level 3 (BOF)
if ($loggedInUser->checkPermission(array(3))){
if ($handle = opendir('CD500/')) {
while (false !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..'){
$thelist .= '<a href="/CD500/'.$file.'" target="_blank" >'.$file.'</a></br>';
}
}
closedir($handle);
echo "
<div id='output'>
List of help files:</div>
<div id='List'>
$thelist ";
}
else {
echo " asdfasdfasdfadf ";
}
}
?>
<div id='default'>
<?php } else { ?>
<li><a class="<?php echo ($page_name=='login.php')?'selected':'';?>" href="login.php">Login</a></li>
<li><a class="<?php echo ($page_name=='register.php')?'selected':'';?>" href="register.php">Register</a></li>
<li><a class="<?php echo ($page_name=='forgot-password.php')?'selected':'';?>" href="forgot-password.php">Forgot Password</a></li>
<?php } ?></div>
The problem lies at your else clause not belonging to your first if statement where you check for user login. I have also changed the code a bit at the point where you need to conditionally print some html. Try the following.
<?php
if (!securePage($_SERVER['PHP_SELF'])){die();}
$parts = parse_url($_SERVER["REQUEST_URI"]);
$page_name = basename($parts['path']);
//Links for logged in user
if(isUserLoggedIn()) {
//Links for permission level 3 (BOF)
if ($loggedInUser->checkPermission(array(3))){
if ($handle = opendir('CD500/')) {
while (false !== ($file = readdir($handle))){
if ($file != '.' && $file != '..'){
$thelist .= '<a href="/CD500/'.$file.'" target="_blank" >'.$file.'</a></br>';
}
}
closedir($handle); ?>
<?php if($thelist): ?>
<div id='output'>
List of help files:
</div>
<div id='List'>
<?php echo $thelist; ?>
</div>
<?php endif; ?>
<?php }
} else {
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
}
} else { ?>
<div>
<li><a class="<?php echo ($page_name=='login.php')?'selected':'';?>" href="login.php">Login</a></li>
<li><a class="<?php echo ($page_name=='register.php')?'selected':'';?>" href="register.php">Register</a></li>
<li><a class="<?php echo ($page_name=='forgot-password.php')?'selected':'';?>" href="forgot-password.php">Forgot Password</a></li>
</div>
<?php } ?>
Related
I'd like to add condition to my code so that after click on label it link me to other page. Now this code link to other article on the website. So I guess what should I add to get from my label to other page.
Thank you for answers!
My code is below:
<ul class="nav nav-tabs aboutUsTabs nav-justified" role="tablist">
<?php foreach ($this->items as $key=>$item ){
if($item['children']){ ?>
<li role="presentation" class="<?php if($item['menu']->id==$this->pageId || $item['menu']->id==$this->parentId){ echo 'active'; } ?>"><?php echo $item['menu']->title;?></li>
<?php }else{ ?>
<li role="presentation" class="<?php if($item['menu']->id==$this->pageId || $item['menu']->id==$this->parentId){ echo 'active'; } ?>"><?php echo $item['menu']->title;?></li>
<?php } ?>
<?php } ?>
</ul>
All this start/stop of PHP code hurts my eyes! Anyways, linking to other pages is done with tags. Not quite sure I understand your question, but you could (if you mean labels for form elements) do something like this;
<label for=""> Something Meaningful </label>
I'm sorry, but I took the liberty to clean up your code a little. Hopefully this will make it more readable;
<ul class="nav nav-tabs aboutUsTabs nav-justified" role="tablist">
<?php
foreach ($this->items as $key=>$item ){
$active = NULL;
if($item['menu']->id==$this->pageId || $item['menu']->id==$this->parentId){
$active = 'active';
}
$menu = NULL;
if($item['menu']->id==$this->pageId || $item['menu']->id==$this->parentId){
$menu = 'active';
}
if($item['children']){
echo'<li role="presentation" class="'.$active.'">
'.$item['menu']->title.'
</li>';
}else{
echo'<li role="presentation" class="'.$menu.'">
'.$item['menu']->title.'
</li>';
}
}
?>
</ul>
For your comment question, if you know what item needs a different value, it could be the title f.ex. then you can check against that value and change the output of your element. Maybe something like;
if($item['children']){
if($item['title'] == 'Unique Identifier for your element') {
// In here you could manipulate the output of that one item you want to exclude/change
} else {
// Your normal output
echo'<li role="presentation" class="'.$active.'">
'.$item['menu']->title.'
</li>';
}else{ ... }
And even better would be to perform the check beforehand, so maybe something like;
$link = '#about-us-page-'.$item['menu']->id;
if($item['title'] == "That identifier") {
$link = 'somethingElse';
}
and then change the value of your href tag to;
'.$item['menu']->title.'
I would like to know how I can do to change the links depending on where I am on my site?
For example, I would like that when I click on "Sign In", it is like this:
Forums > Sign In
http://prntscr.com/47d04a
container.php:
<div class="wrapper">
<div id="container">
<div id="breadcrumb_top">
<div class="breadcrumb_links">
<ul>
<li class="forums">
Forums
</li>
</ul>
</div>
</div>
<?php
if(strpos($_SERVER["REQUEST_URI"], "index") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Forums</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "members") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Members</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "sign_up") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Sign Up</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "sign_in") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Sign In</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "change_theme") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Change Theme</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "contact_us") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Contact Us</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "help") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Help</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "rules") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Rules</h1>";
/* Code here. */
}
?>
<div id="breadcrumb_bottom">
<div class="breadcrumb_links">
<ul>
<li class="forums">
Forums
</li>
</ul>
</div>
</div>
</div>
</div>
I would like that everything be automated depending on where I am. If I click on "Members" in the top_bar, I would like that "Forums" in the breadcrumb should be replaced by "Members", etc.
Thanks.
At the top of my pages I'll create some PHP variables or constants that describe what the page name, parent and title are and then use a function to determine what page I'm on by what's defined/set.
This is an idea of what it's like.
<?php
define('PARENT','Blog'); // the site section/parent
define('PAGE','Posts'); // the child page under the site section
$page_title = 'My Blog'; // the page's title
function active($str, $submenu='') {
if(!defined(PARENT) || !defined(PAGE)) {
return false;
}
if($submenu) {
if($str == PARENT) {
return ' visible';
}
} else {
if($str == PARENT || $str == PAGE) {
return ' class="active selected"';
}
}
return false;
}
echo $page_title;
?>
<ul class="submenu<?php echo active('Blog', 'submenu') ?>">
<li<?php echo active('Posts') ?>>
Posts
</li>
</ul>
I am having a problem with trying to show different menu options based on UserLevel. I have a mysql database with a users table. The users table contains a UserLevel which will either be set to 0 or 1. But for some reason my php just isn't working. In fact, when I add the php to the menu, it then does not display ANYTHING on the site below the menu. Any advice would be much appreciated.
Code that starts session
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
?>
<?php include "mainNav.php"; ?>
<center>
<h2> Campaign Updates</h2>
</center>
<div id="campaignPostWrap">
<div id="campaignScrollBox">
<?php
$con=mysqli_connect("localhost","dorians","ds2953!b67P$","aldentec");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM campaigns ORDER BY postDate desc");
while($row = mysqli_fetch_array($result))
{
echo "<div id='campaignPostContainer'>";
echo "<ul class='campaignPostBox'>";
echo "<p class='postInfo'>";
echo "Posted on:";
echo "<li>" . $row['postDate'] . "</li>";
echo "</p>";
echo "<p class='postInfo'>";
echo "Posted by:";
echo "<li>" . $row['postName'] . "</li>";
echo "</p>";
echo "<li class='postEntry'>" . $row['postEntry'] . "</li>";
echo "</ul>";
echo "</div>";
echo "<hr>";
}
mysqli_close($con);
?>
</div>
<?php include "campaignPost.php"; ?>
</div>
<?php include "chat.php"; ?>
<?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
if(mysql_num_rows($checklogin) == 1)
{
$row = mysql_fetch_array($checklogin);
$email = $row['EmailAddress'];
$userlevel = $row['UserLevel'];
$_SESSION['Username'] = $username;
$_SESSION['EmailAddress'] = $email;
$_SESSION['LoggedIn'] = 1;
$_SESSION['UserLevel'] = $userlevel;
echo "<h1>Success</h1>";
echo "<p>We are now redirecting you to the member area. If you are not automatically redirected <a href='index.php'>Click here</a></p>";
header( "refresh:10;url=index.php" );
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your account could not be found. Please click here to try again.</p>";
}
}
else
{
?>
Menu code that isn't working
<?php session_start(); ?>
<?php
$userlevel = $_SESSION['UserLevel'];
if($userlevel == 0) {
echo "<ul class="mainNav">
<li> Create Character</li>
<li> Create Quest</li>
<li> View Characters</li>
<li> View Quests</li>
<li> Book List</li>
</ul>";
} elseif($userlevel == 1) {
echo "<li> DM Tools</li>";
}
?>
<?php include "greeter.php"; ?>
Your quotes are undoubtedly the problem here:
if($userlevel == 0) {
echo "<ul class="mainNav">
<li> Create Character</li>
<li> Create Quest</li>
<li> View Characters</li>
<li> View Quests</li>
<li> Book List</li>
</ul>";
} elseif($userlevel == 1) {
echo "<li> DM Tools</li>";
}
Notice the syntax highlighting above shows the issue in your string. See how it turns black when it gets to mainNav? That's because mainNav is no longer part of the string. That's a bad thing here.
Look at the first line of your echo:
echo "<ul class="mainNav">
You open a quote and then close it at class=". Now, it's trying to evaluate mainNav as a constant or some other language construct. On top of that, it doesn't know what to do with mainNav as you haven't provided any kind of operators.
Instead, you should do something like:
if($userlevel == 0) {
echo '<ul class="mainNav">
<li> Create Character</li>
<li> Create Quest</li>
<li> View Characters</li>
<li> View Quests</li>
<li> Book List</li>
</ul>';
} elseif($userlevel == 1) {
echo '<li> DM Tools</li>';
}
Alternatively, you could escape every location where there is a non-string-terminating quote like \".
Another option would be to use Heredoc syntax.
I am trying to return a $user_id variable from file to if(isset(...)) statement. I will perform a different if statement but just trying to echo out the $user_id variable to test that I am setting the page.
<?php
include 'core/init.php';
include 'init.image.php';
protect_page();
include 'includes/overall/overall_header.php';
if(isset($_GET['username']) === true && empty($_GET['username']) === false){
$username = $_GET['username'];
if(user_exists($username) === true){
$user_id = user_id_from_username($username);
$profile_data = user_data($user_id, 'first_name','last_name','email', 'username');
?>
<h1><?php echo $profile_data['first_name']; ?>'s Yor Page</h1>
<div id="navWrapper">
<ul>
<li>
<img src="uploads/profile/blank_profile.gif" width="150" height="150" id="blank_profile">
</li>
<nav>
<ul>
<li>
Albums
</li>
<li>
Music
</li>
</ul>
</nav>
</ul>
</div>
<?php
if(isset($_GET['action']) && $_GET['action']=='albums'){
$albums = get_profile_albums($user_id);
if(empty($albums)){
echo 'No Albums';
}else{
foreach($albums as $album){
if (empty($album['image'])) {
$album['image'] = 'uploads/profile/blank_profile.gif';
}
?>
<p><?php echo $album['name'],' (', $album['count'], ')'?> <br />
<a href="<?php echo $profile_data['username'];?>?action=album_id=<?php echo $album['id'];?>">
<img src="uploads/thumbs/<?php echo $album['id'];?>/<?php echo $album['image'];?>" />
</a><br />
<?php echo $album['description'];?>...<br />
</p>
<?php
}
}
}
if(isset($_GET['action']) && $_GET['action']=='album_id=$album['id']'){
echo $user_id;
}
if(isset($_GET['action']) && $_GET['action']=='music'){
echo'<h1>Music</h1>';
}
}else{
echo 'Sorry, that user doesn\'t exist';
}
}else{
header('Location: index.php');
exit();
}
include 'includes/overall/overall_footer.php';
?>
Single quotes do not parse the string but double quotes do. For example:
$album_id = 1;
echo 'album_id=$album_id ';
echo "album_id=$album_id";
Will result in album_id=$album_id album_id=1
Thus, $_GET['action']=='album_id=$album_id' is checking if $_GET['action'] is equal to 'album_id=$album_id' and not what $album_id is evaluated to.
Your check should be more along these lines:
if (/* ... */ && $_GET['action']=="album_id=$album_id") {
Edit: Suggestion.
You should check $_GET['action'] once and store $action. From there create an if/else if/else statement checking each possible type of action (music, albums, album, etc). If a type of action requires extra user supplied data, include that in the respective if block. For example:
$action = $_GET['action'];
// URL: /script.php?action=albums
if ($action == 'albums') {
// ...
}
// URL: /script.php?action=album&album_id=12
else if ($action == 'album') {
if (!empty($_GET['album_id'])) {
$album_id = $_GET['album_id'];
echo "User with id $user_id is trying to access album with id $album_id";
}
// ...
}
// ...
No more $_GET['action']=="album_id=$album_id"
You are passing the variable correctly.
What I'm more concerned with in the following line is:
if(isset($_GET['action']) && $_GET['action']=='album_id=$album_id'){
'album_id=$album_id' doesnt look right and is probably why your if is not firing... It looks like you're trying to use the variable $album_id wrapped in single quotes and that will not substitute the value and rather keep $album_id in tact. I'm not sure if this is what you intended but if not its likely the source of your problem.
looking for some help:)
http://69.65.3.168/~doubleop/pro.sperity/blog
is the site i am working on, you can see the navigation is a drop down. I want the green to hover over active pages.
This is a drop down menu, so i created parent pages as the main nav links, and the drop down contains child pages.
All the links are hard coded at the moment, not using wordpress' built in function.
This is my code for the active links, which works well on normal .php sites, but not on wordpress
<ul id="menu">
<li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'index') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?>>Home
<!--No drop downs-->
</li>
<li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'blog') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> >Blog
<!--No drop downs-->
</li>
<li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'business-model') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> >Business Model
<ul>
<li>Introduction</li>
<li>Investment Strategy</li>
<li>Investor Benefits</li>
<li>Investment Programs</li>
<li>Prosperity Partnership</li>
<li>RRSP Investment</li>
<li>Limited Partnership</li>
<li>Refferal Program</li>
<li>FAQ</li>
</ul>
</li>
<li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'track-record') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> >Tack Record
<ul>
<li>Company Overview</li>
<li>Investment Portfolio</li>
<li>Why Prosperity</li>
<li>Testimonials</li>
</ul>
</li>
<li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'current-oppertunities') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> >Current Oppertunities
<ul>
<li>Current Offerings</li>
<li>Investor Interest Form</li>
<li>Properties for Rent</li>
</ul>
</li>
<li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'upcoming-events') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> >Upcoming Events & News
</li>
<li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'mentorship-program') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> >Mentorship Program
</li>
<li <?php $string = basename($_SERVER['SCRIPT_FILENAME']); if ( strpos($string, 'about-us') !== false ){ echo "class='active'"; }else{ echo "class='nactive'"; } ?> >About us
<ul>
<li>Mission Statement</li>
<li>Management Team</li>
<li>Contact</li>
</ul>
</ul>
(the code is showing up wierdly, but you get the idea)
I tried echoing out the script_filename, and it was index.php on every page.
Anyone know how i can go about doing this? I need the active state to stay there when the user is on the relevant page, or any relevant child pages within under the parent
Thank you
$_SERVER['SCRIPT_FILENAME'] is the same on every page since Wordpress directs all pages to the same script for processing.
If you want to search the URI for a specific string, try using $_SERVER['REQUEST_URI'] instead; that returns the requested URI, regardless of which script is being executed.
Also, in the code supplied, you misspelled "inactive" as "nactive."