Hiding GET parameters in php - 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.

Related

How to Overcome Undefined Variable Dicodeigniter

I want to put the photos in the uploads folder but when I try to call the variable from the controller to the view it generates an Undefined Variable error
File : application/controllers/ubah_profile.php
public function ubah_profile()
{
$data['foto'] = $this->db->get_where('user',array('id'=>$this->session->userdata('id')),1)->row()->foto;
$this->load->view('top',$data);
$this->load->view('upload_foto');
$this->load->view('bottom');
}
File : application/views/top.php
<ul class="nav navbar-nav">
<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="<?php echo base_url() ?>uploads/<?php echo $foto; ?>" class="user-image" alt="User Image">
<span class="hidden-xs">Admin</span>
</a>
</li>
</ul>
You should change the form type my friend.
That’s why the controller can’t recieve the file info.
Btw, judulnya ada campuran bhs indo wkwk.

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;

Links from require_once broken

I have a menu file that i want to include in every file of my site to avoid writing every time the same code. I do this with require_once("menu.php"); The problem is that when i click on a link generated by menu.php it results to be a relative link instead, because it doesn't find the file.
This is my directory:
menu.php:
<?php echo'
<div class="topnav-bar">
<ul class="topnav">
<li class="dropdown">Home
<ul class="dropdown-content">
<li>Geografia</li>
<li>Clima</li>
<li>Storia</li>
</ul>
</li>
<li class="dropdown">Luoghi
<ul class="dropdown-content">
<li>7 Chiesette</li>
<li><a href="pages/luoghi/catajo.php" class="active">
Castello del Catajo</a></li>
<li>Abbazia di Praglia</li>
<li><a href="pages/luoghi/carrareseeste.php">
Castello carrarese di Este</a></li>
<li>Castello di Lispida</li>
<li>Castello San Pelagio</li>
</ul>
</li>
<li class="icon">
☰
</li>
</ul>
</div>'; ?>
if from "index.php" i click on "chiesette.php" for example, the browser shows me the url http://127.0.0.1/pages/luoghi/chiesette.php. Now if from this page i click on "catajo.php" it shows me http://127.0.0.1/pages/luoghi/pages/luoghi/catajo.php.
What am i doing wrong?
When you are in index.php you are at the root so the link will refers to the right location.
From /pages/luoghi because of the lack of slash, it builds the link from you actual directory, eg /pages/luoghui
<li>7 Chiesette</li>
<li><a href="/pages/luoghi/catajo.php" class="active">
Castello del Catajo</a></li>
<li>Abbazia di Praglia</li>
<li><a href="/pages/luoghi/carrareseeste.php">
Castello carrarese di Este</a></li>
<li>Castello di Lispida</li>
<li>Castello San Pelagio</li>
THe code above (whith slashes) should work because the link will be build from root.

Bootstrap dropdown stop working after php die

Hi i have a script in which there are bootstrap dropdowns. The code for it is as follows:-
<ul class="nav navbar-nav navbar-right">
<li class="dropdown dropdown-user" style="font-size:15px;">
<a class="dropdown-toggle" data-toggle="dropdown">
<i class="icon-user"></i> <span><?php echo $name; ?></span> <i class="caret"></i></a>
<ul class="dropdown-menu dropdown-menu-right width-220">
<li><i class="icon-lock2"></i> Change Password</li>
<li><i class="icon-switch2"></i> Logout</li>
</ul>
</li>
</ul>
Now i run a php script after a form is submitted in which i am checking whether a table is there in the database or not. If it is there it fethces it and if it is not there php script dies. The code for it is below:-
<?php
if(isset($_POST['submit']))
{
$sql="SELECT * FROM table1";
$results = $con->query($sql);
if ($results === FALSE) {
echo "<script> noty({text: 'No Data Found',layout: 'topRight',timeout: 3500,closeWith: ['click', 'hover'],type: 'error'});</script>";
die();
} else {
........
}
Now whenever the php script dies the dropdowns stop working.
I am just starting to learn php so please let me know what I am doing wrong or if there is a better way of looking at this problem. Any help is highly appreciated.
Check if you included bootstrap js file at the end of your page.
So when PHP dies, The bootsrap will not be loaded to the page. If its the reason change die with something else or move bootstrap js file to header.
PS:Besides use die whenever something goes wrong is not the best idea to handle errors.

Catch the URL and redirect somewhere else

i ve done this below menu in php which is autogenerated with a function :
As you know, if i click on "Red Chicken", it will try to open a ../Red%20Chicken URL, which doesnt exist till it comes from a big table which change everytime.
What i want to do is : to know where we clicked (example : by generating the url and cut it ) and then redirect to a page like result.php (+ get something like the variable to know where do we come from). And of course, i don't want to create a .php page for each element of my table.
Is this thing possible ?
EDIT : i found a way, it's to change my function and how it generates the menu.
Not really what i wanted but it's okay.
<ul class=\"niveau1\">
<li class=\"sousmenu\"><a href=\"Food\">Food</li>
<ul class=\"niveau2\">
<li class=\"sousmenu\">Meat</li>
<ul class=\"niveau3\">
<li class=\"sousmenu\">Poultry</li>
<ul class=\"niveau4\">
<li class=\"sousmenu\">Red Chicken</li>
</ul>
</ul>
<ul class=\"niveau3\">
<li class=\"sousmenu\">Beef</li>
<ul class=\"niveau4\">
<li class=\"sousmenu\">Hamburgers</li>
</ul>
<ul class=\"niveau4\">
<li class=\"sousmenu\">Steak</li>
</ul>
</ul>
</ul>
<ul class=\"niveau2\">
<li class=\"sousmenu\">Dairy</li>
<ul class=\"niveau3\">
<li class=\"sousmenu\">Cow</li>
</ul>
<ul class=\"niveau3\">
<li class=\"sousmenu\">Sheep</li>
</ul>
</ul>
</ul>
<ul class=\"niveau1\">
<li class=\"sousmenu\">name</li>
</ul>
http://jsfiddle.net/w10j0a38/1/
The PHP-Way would probably be to use URLs like <a href='menuhandler.php?sel=cow'>Cow</a>, and if you want to be lazy, you could also JS/jquery to manupulate the URLs and replace <a href="something">with a call in the style shown before - but then this would not work w/o JS, so it is not a real option IMHO.
changed my function to generate it in another way
<a href=\"Recette.php?var=food\">
Not really what i wanted but it's okay.

Categories