after puttin php syntax, my website get stuck at preloader - php

I have this code on my php file for navbar:
<?php if(!$session->is_logged_in()) {
echo '
<a href="login.php" role="button" aria-expanded="false">
Login <span class="label"> login to system</span> </a>
</li>';}
else
{
echo '
<a href="#!" class="dropdown-toggle" role="button" aria-expanded="false">
' . $session->user_name; . '<span class="badge bg-default">2</span> <span class="caret"></span> <span class="label">it is you</span>
</a>';
}
?>
I check if the session is set using (!$session->is_logged_in())
If it is not set I should get a login button on navbar.
If the session is set, I should get his username ($session->user_name).
On my website I have a preloader (astral-gaming.com) but after inserting this code and uploading this file, every page which had included it, isn't shows.
It's just the preloader and it doesn't go to the page.
After deleting that code, everything is fine.
What I should do?

Remove the ; after$session->user_name;

Related

echo $user->roles[0]; in WordPress menu navigation

At the beginning I want to say that all the code presented below works well if put in right environment. I only have an issue with php in wordpress menu navigation that seems not to be able to work.
I'm trying to print user's role (there's only one role a user can have at a time) in a dropdown. PHP code:
<?php
$user = wp_get_current_user();
echo $user->roles[0]; ?>
dropdown code:
<ul id="primary-menu" class="navbar-nav ml-auto"><li class="nav-item menu-item menu-item-type-gs_sim menu-item-object-gs_sim">(Untitled)<small class="description"></small><small class="description"><div class="dropdown show"><a href="" class="nav-link">
</a><a class="nav-link btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<img src="http://ds.com/wp-content/uploads/ultimatemember/1/profile_photo-40x40.png?1561371663" class="gravatar avatar avatar-40 um-avatar um-avatar-uploaded" width="40" height="40" alt="pzo3xic" data-default="http://ds.com/wp-content/plugins/ultimate-member/assets/img/default_avatar.jpg" onerror="if ( ! this.getAttribute('data-load-error') ){ this.setAttribute('data-load-error', '1');this.setAttribute('src', this.getAttribute('data-default'));}"> pzo3xic
</a>
<div class="dropdown-menu show" aria-labelledby="dropdownMenuButton">
<h6 class="dropdown-header" href="/user/">Paid Subscriber</h6>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/profile">View Profile</a>
<a class="dropdown-item" href="/private-lessons">Private Lessons</a>
<a class="dropdown-item" href="/logout">Log Out</a>
</div>
</div></small></li>
<li class="nav-item menu-item menu-item-type-taxonomy menu-item-object-category">Lessons</li>
<li class="nav-item menu-item menu-item-type-post_type menu-item-object-page">Tests</li>
</ul>
I want it to present as below (where "Paid Subscriber" is the user's role name):
But when I replace "Paid Subscriber" with my custom shortcode "[print_user_role]" it kind of displays the text instead of the function within. Let me point out here that my shortcode works well when added into other places.
Problem:
The avatar along with dropdown are all in a code added via Shortcode in Menus plugin. This plugin (and all the others) don't support php inside.
I have tried adding a shortcode into my custom_functions.php, then invoking it by pasting [my_custom_function_sc] into the code, however it returned nothing.
I lost ideas on how to achieve this effect. Does any of you see a possible solution here?
EDIT
I think that I might actually print the user's role somewhere else within a certain block, then with jquery copy the text within the block and paste in place that interests me. Does any of you have any ideas on how to achieve this? I haven't used javascript/jQuery really.
Many thanks
Your code seems to be correct except this line --> echo $user->roles[0];
The correct code is --> echo $user->roles;

Anchor Tag automatically calling href Without Click in Codeiginitor

Here in My View:
<div class="dropdown">
<button class="btn dropdown-toggle" type="button" data- toggle="dropdown">Dropdown Example
<span class="caret"></span></button>
<ul class="dropdown-menu">
<?php
foreach($site as $sites)
{
echo '<li >"'.$sites->site_title.'" </li>';
}
?>
</ul>
</div>
<?php
}
?>
i want to redirect when user click on $sites->site_title
but how it working is it automatically redirects to url
enter code here"<li><a href='shop/viewSiteId?id=".$sites->site_id."'>".$sites->site_title."</a></li>";
and get that id by using GET method
A redirect is the programmatic way to send a browser to a URL. In other words, a call to redirect is like clicking a link. They are not intended to work together in the way you have tried.
<?php
foreach($site as $sites) : ?>
<li>
<a href='<?= base_url("shop/viewSiteId?={$sites->site_id}"); ?>'><?=$sites->site_title; ?></a>
</li>
<?php endforeach;
If you are not familiar with the syntax, know that <?= is the shortcut way to write <?php echo
I've also used PHP Alternative Syntax for Control Structures and dropped in and out of the PHP processor a bunch of times. For me, that is the easier way to read and write this kind of thing. (Your mileage may vary.)

How to display html link element inside php script

I am trying to include a php variable inside this php script that displays an html link. What i need is to include my php $row['vin'] variable in the href html link after the ? to pass a value to the page i am linking to. Top code block works but i still need that php variable, bottom is an example of what ive tried which will not work.
Works but missing my php variable:
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
Does not work:
<td>
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?'. $row['vin']">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
</td>
You've forgotten the rest of the concatenation logic. It's just a syntax error:
<td>
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?'. $row['vin'] . '">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
</td>
An alternative to using PHP to echo out great chunks of mostly static content is to instead, drop in and out of the PHP context (ie <?php ... ?>) when necessary and use it like a templating language.
For example
<td>
<?php if ($row['instock'] == "Yes"): ?>
<a href="orderForm.php?<?= htmlspecialchars($row['vin']) ?>">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<?php endif ?>
</td>
See http://php.net/manual/control-structures.alternative-syntax.php

sending user a mesage by passing their id to a modal box

I am trying to create a message form into a bootstrap modal by Passing the user username/id to the modal for identification.
here is an html/php code that made a list of registered users.
<div class="col-lg-4 col-md-4 col-sm-4 mb">
<div class="content" style="margin-bottom:5px;">
<ul class=" extended inbox">
<div class="notify-arrow notify-arrow-green"></div>
<li>
<p class="green">People you can follow</p>
</li>
<?php
//Show all users
foreach ($users as $row) {
?>
<li style="padding:3px; margin-bottom:3px; width:100%; background:#CF9;">
<a href="index.html#">
<span class="photo" style="float:left; padding:4px;"><img alt="avatar" src="uploads/<?php echo $row['pix']; ?>" width="50" height="50"></span>
<span class="subject" style="float:left;">
<span class="from">
<?php
echo ''.$row['user_lastname']. ' '.$row['user_firstname'].'';
?>
<a class="" data-toggle="modal" data-target="#profile_pic_modal"><span class="glyphicon glyphicon-comment"></span></a>
</span><br>
<span class="time">
<?php
echo (($row['receiver'] === $row['user_id'] && $row['sender'] === $user_id)
? '<button class="btn follow following " rel="'.$row['user_id'].'">Following</button>'
:' <button class="btn follow" rel="'.$row['user_id'].'">
<i class="fa fa-user-plus alert-info"></i> Follow </button>');
?>
</span>
</span>
</a>
</li><br>
<?php
}
?>
</ul>
</div>
When a user click on another user's message icon he/she should be able to send message. Could someone please show me how to do this using php/mysqli and ajax
First add a data-(anyName) tag like below
<?php $ID = 'The persons Username'; ?>
<a href='#' class='btn btn-warning btn-xs open-AddBookDialog' data-id='$ID' data-toggle='modal'>My Modal</a>
Then put a input tag inside your modal body with a ID of example(MyID)
<input type="text" id="MyID">
Then using the code below (jquery) this will pass the value of data-id into that input tag on modal show.
$(document).on("click", ".open-AddBookDialog", function () {
var myId = $(this).data('id');
$(".modal-body #bMyID").val(myId);
$('#myModal').modal('show');
});
Information like username (login?) and id of a logged user should be disposed by Session, unlike you have good reasons for not do that. When the user enters in the system, you will already load a bunch of data to be sure he is valid, so the practical way to not retrieving always all the data from the user logged in, that are currently using your system, it's always good to use SESSIONs to handle that (imagine a ton of users using your system and you needing to retrieve each of them to each click and routine inside the system).
In a practical way, just open your modal and validate your routine using the started session with the user information settled in.
To clarify about the OTHERS users data (those listed that the current user will click to send a message) you can have to methods:
YOUR HTML:
<a href="#" data-userid='<?= $row['user_id']; ?>'>
<span class="photo" style="float:left; padding:4px;"><img alt="avatar" src="uploads/<?php echo $row['pix']; ?>" width="50" height="50"></span>
<span class="subject" style="float:left;">
<span class="from">
<?php
echo ''.$row['user_lastname']. ' '.$row['user_firstname'].'';
?>
<a class="" data-toggle="modal" data-target="#profile_pic_modal"><span class="glyphicon glyphicon-comment"></span></a>
</span><br>
<span class="time">
<?php
echo (($row['receiver'] === $row['user_id'] && $row['sender'] === $user_id)
? '<button class="btn follow following " rel="'.$row['user_id'].'">Following</button>'
:' <button class="btn follow" rel="'.$row['user_id'].'">
<i class="fa fa-user-plus alert-info"></i> Follow </button>');
?>
</span>
</span>
</a>
#Modal (Assuming you're using v4)
<div class="modal hide fade" id="user-message">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3 class="hdrtitle">Hey <?= $_SESSION['login']; ?>, Send message to <span></span></h3>
</div>
<div class="modal-body">
<label for='msg'>Message:</label>
<textarea id='msg' rows="4" cols="50" name='msg'></textarea>
<button id='send-msg'>Send Msg</button>
</div>
</div>
and then showing it with:
$('a').on('click', function(){
//retrieve all other user data
$.get( "yourcode.php?userid=" + $(this).data('userid'), function( data ) {
$('.modal h3 span').html(data.username);
//FILL YOUR MODAL AS YOU WISH
$('.modal').modal('toggle');
});
});
But the best way is to click and mount the modal in a partial view bringing the HTML already mounted with all information you want just to trigger the modal routine, avoiding html structure that the user don't really needs at first time access the page.
$('a').on('click', function(){
//retrieve all other user data
$.get( "partialmodal-sendmsg.php?userid=" + $(this).data('userid'), function( data ) {
$('body').append(data);
//FILL YOUR MODAL AS YOU WISH
$('.modal').modal('toggle');
});
});
Some must reads about:
When should I use session variables instead of cookies?
http://cse.unl.edu/~riedesel/pub/cse413/Project%202/SESSION.pdf

Hiding GET parameters in php

I am working on local machine and my URL is:
http://localhost:91/GlobalVision/index.php?mm=1&sm=1
<? $mm=$_GET["mm"];
$sm=$_GET["sm"]; ?>
<ul class="sidebar-menu">
<li class="header">MAIN NAVIGATION</li>
<li class=" <? if($mm==1) echo "active" ?> treeview">
<a href="#">
<i class="fa fa-dashboard"></i> <span>Dashboard</span> <i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li <? if($mm==1 && $sm==1) echo "class=\"active\"" ?>><i class="fa fa-circle-o"></i> Dashboard1</li>
<li <? if($mm==1 && $sm==2) echo "class=\"active\"" ?>><i class="fa fa-circle-o"></i> index2</li>
</ul>
</li>
</ul>
i have created this file as separate menu file and included in other php files.
i wanted url as:
http://localhost:91/GlobalSDK/index
I tried writing:
^([a-zA-Z]+)/$ index.php?mm=$1&sm=$2 [L]
this rules in .htaccess file but it gives me error.
What should be the rule to achieve this. Even when index page get change it should display only page name not parameters. What should be the rule for this?
Try these methods
1) Use a form and POST the information.
2) Use session variables to carry information from page to page.
3) Use "encoded" or non-sensical information in the QueryString in
place of the real data.

Categories