I have an admin link with a div id "admin". Sessions are started when a user is logged in to show if it is a normal user or an admin. Normal users can't access the files for admin, but can still see the admin link.
Is there a way to make it so normal users can't see the link, using only php or html, without jquery or jscript or any of those.
Using interleaved PHP & HTML with standard PHP syntax:
<?php
if ($user_is_an_admin) {
?>
<div id='admin'>
Only admins can see this...
</div>
<?php
}
?>
Alternate templating syntax:
<?php if ($user_is_an_admin): ?>
<div id='admin'>
Only admins can see this...
</div>
<?php endif; ?>
Not interleaving, PHP only:
if ($user_is_an_admin) {
echo "<div id='admin'>
Only admins can see this...
</div>
";
}
You'll need to use conditionals inside of your views:
<?php if($_SESSION['adminid'] == 1234): ?>
<!-- Admin div goes here -->
<?php else: ?>
<!-- Admin link goes here -->
<?php endif; ?>
Related
I have a problem with PHP. When user is logged in, or session is started,
I want to hide div class, which is button "Login".
How can I make this with PHP?
Instead of trying to hide it, never output the div if the session has login information.
I.e. in your template / code that's outputting the HTML, check if the session is present (you'll have to swap user with whatever key you're storing the valid login under):
<?php
if (empty($_SESSION['user'])):
?>
<div class="login"> ... </div>
<?php
endif;
?>
.. and if you need it in a function:
<?php
function show_login_if_unknown() {
if (empty($_SESSION['user'])) {
echo '<div class="login"> ... </div>'; // or use ?> ... <?php
}
}
I received this request from my client:
"We are still experiencing LOTS of problems with state aid recipients trying to log into their state aid account through the “My Account” function, even though you added language to direct them elsewhere. To solve this problem, would it be possible to remove the “Student Disability”, “Contact Us”, and “My account” links from the top of the State Aid pages? "
In researching and found that those links are generated in the searchform.php file of my theme.
How do I exclude that page from applying the get_search_form() function in the head.php? This is what the navigation looks like with that function:
<div id="top-navigation">
<?php get_search_form(); ?>
</div>
This is the site: http://Riseupms.com/state-aid/
Is it possible?
Assuming that the Page name of that particular page is "STATE FINANCIAL AID" you can do it like this
<?php if(!is_page( 'STATE FINANCIAL AID' ) { ?>
<div id="top-navigation">
<?php get_search_form(); ?>
</div>
<?php } ?>
or you can exclude it by page id like this
<?php if(!is_page( 2341 ) { ?>
<div id="top-navigation">
<?php get_search_form(); ?>
</div>
<?php } ?>
or u can simply do it with css
body.page.page-id-2341 #nav-bar li#item1,
body.page.page-id-2341 #nav-bar li#item2,
body.page.page-id-2341 #nav-bar li#item3 {
display:none;
}
This is my php code
<?php
require_once('../includes/config.php');
// include file to check, If current user loggedin or not
include('log-security.php');
require_once('../cs/includes/header.php');
if(in_array(cms_username, $allowedUsers))
{
$allowedUsers=['john', 'akhil'];
<div id="view8"></div>
}
?>
This is my div id code
<div id="view8" class="tabcontents">
<h3>Creation of files</h3>
</div>
Im new to PHP, Please help me to correct the code if its wrong .
while login only it should restrict the user.when allowed user is entered then the viewid should displayed for others it should not.
Try something like that :
<?php
require_once('../includes/config.php');
require_once('../cs/includes/header.php');
include('log-security.php');
$allowedUsers = array('john', 'akhil');
?>
<?php if (in_array('cms_username', $allowedUsers)): ?>
<div id="view8" class="tabcontents">
<h3>Creation of files</h3>
</div>
<?php endif; ?>
I need some links (related to user account) to appear on the index page for the user who logged in. i have a session variable'email'.
i did this but it didn't work.
<div id="left">
left div content
</div>
<div id=-"right">
<?php
if(isset($_SESSION['email']))
{
?>
//show user some links to his account.
<?php
}
else
{
?>
//show login and register forms
<?php
}
?>
</div>
<?php
session_start(); // add this line
if(isset($_SESSION['email']))
{
?>
Link to php manual.
your first statement within the
<?php
session_start();
//followed by rest of the code.
?>
should be
session_start();
Then the further code.
I have plugin by WPMU that creates a membership system for your wordpress theme. Im trying to make it display a gallery only when a user is a premium member and Im completely lost. My code basicly grabs part of the url and pastes it into variables in my susbscription div to draw the information needed. I need it to check if the user is logged in but Im not sure how to do that. Here is my code, Thanks:
<?php get_header(); ?>
<?php
$url = $_SERVER['REQUEST_URI'];
$url = rtrim($url, '/');
function drawId($url) {
return array_pop(explode('-', $url));
}
?>
<div class="main-container col2-right-layout">
<div class="main">
<p><?php echo drawId($url); ?></p>
<?php get_template_part('loop');?>
<div id="subscription">
<p><?php echo nggcf_get_gallery_field(drawId($url), "Gallery Text"); /* where 1 is the gallery id */ ?></p>
<?php echo do_shortcode('[nggallery id='.drawId($url).']');?>
</div>
</div><!-- .main -->
</div><!-- .main-container col2-right-layout -->
<?php get_footer(); ?>
The following is copied and pasted from the plugin's support forms:
you can try any of the following for your customization needs:
current_user_is_member()
current_user_on_level($level_id)
current_user_on_subscription($sub_id)
And of course, you can get the level_id and sub_id from the respective membership level and subscription lists.
if you want to check if a user is logged in, in wordpress, it is just a condition like this:
if(is_user_logged_in()){
//do you stuff
}
hope this help. read more here
This plugin allows only people that are logged in to your site to use the site:
http://wordpress.org/extend/plugins/private-wp/
Maybe by creating memberships though your admin panel you could target the the user in that way.