I have this link in my db.php. I want everytime the dropdown menu is clicked it redirect to the corresponding page.
$ROOT_URL = '192.167.1.67/office/';
I want to go to this root url on the navigation every time i click on the link.
Home
<ul class="dropdown-menu">
<li>Add Product</li>
<li>View Product</li>
<li>Removed Product</li>
</ul>
instead the page is redirecting as
192.168.1.67/admin/192.168.1.67/admin/product/addproduct.php
How can i solve this problem??
use protocol before your url like..
$ROOT_URL = 'http://192.167.1.67/office/';
OR if having https $ROOT_URL = 'https://192.167.1.67/office/';
If the link points to a local location, you can just use / as root.
This, for examples will work:
Home
If $ROOT_URL is dynamic and you want to include the variable, define it as:
$ROOT_URL = '/office/';
Then you can do:
Home
Also, the links in the list
<ul class="dropdown-menu">
<li>Add Product</li>
<li>View Product</li>
<li>Removed Product</li>
</ul>
point to a relative URL, so when your current URL is /office, the links will point to: /office/addproduct.php. But if this navigation is also included on a page where the URL is /some/other/url, this link will point to: /some/other/url/addproduct.php.
Unless you are really sure the HTML with the link will only show at a certain path, try to avoid relative URLs.
Related
I have finish all my html pages and now I want to add them inside the header.php.
Please see the code below:
<li class="menu-item"> AboutUs </li>
As you can see Iam using the_permalink function to call the html file , but when I click in the navbar the aboutus nothing happen , I dont get the aboutus.html.
Can you please tell me how to ge to my point?
You do not output anything from PHP. Change <?php to <?=:
<li class="menu-item"> AboutUs </li>
<li class="menu-item"> AboutUs </li>
$location_of_file will contain address to aboutus.html file without slash at the end.
I have written some code that will highlight a link in the header based on: class="active". The class is connected to some CSS code to style it.
I am currently adding the class="active" the specified link for each page. However, since I want to move my header into it's own file and include it on each page, I will lose the ability to set the class for each page. I could of course add a variable that will allow me to sort of do the same thing.
What I wish to know is if there is a better and secure way to automatically set the class="active" to the page that I am on. I have seen some posts that suggest using: ($_SERVER['PHP_SELF'] but I have read that it could cause some security issues.
Lastly the main problem that I have is that I need to set two links to
class="active" if I am viewing a page that is in the portfolio list item. For instance, if games.html is currently viewed, both the games and the portfolio page should have the code: class="active".
(All of my .html files are read as .php)
Here is the html code I have so far:
<ul>
<li>Home</li>
<li><a class="active" href="portfolio.html">Portfolio</a>
<ul>
<li><a class="active" href="games.html">Games</a></li>
<li>2D Art</li>
<li>3D Models</li>
<li>Particles</li>
<li>Shaders</li>
<li>Environments</li>
<li>Programming</li>
<li>Substance Designer</li>
<li>Music</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
<li>Store</li>
</ul>
Any help will be appreciated!
PHP_SELF is safe when you only use it to compare values and don't directly use it in your html:
The portfolio menu can be made active by nested all related pages in a folder called portfolio and checking if the path starts with that folder.
<?php
$currentPage = $_SERVER['PHP_SELF'];
$portfolioFolder = 'portfolio/';
$isPortfolioFolder = substr($currentPage, 0, strlen($portfolioFolder)) == $portfolioFolder);
?>
<ul>
<li>Home</li>
<li><a class="<?= $isPortfolioPage ? 'active' : '' ?>" href="portfolio.html">Portfolio</a>
<ul>
<li>Games</li>
<li>2D Art</li>
<li>3D Models</li>
<li>Particles</li>
<li>Shaders</li>
<li>Environments</li>
<li>Programming</li>
<li>Substance Designer</li>
<li>Music</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
<li>Store</li>
</ul>
Im creating website using PHP for the backend. I created a "Common" folder that stores my navigation bar that i'll be using throughout the application. In the navigation bar there are links that redirect users to different pages of the website.
The pages the user will be directed to are in different folders and subfolders of their own. When i click on the navbar link, it redirects to the page. Thereafter, when i click on another navbar link from that page i get a "Object not found" error.
These are the main links:
<li class="nav-item">
<a class="nav-link" href="Views/view_Catalogue.php">PRODUCTS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Views/view_BecomeCustomer.php">BECOME A CUSTOMER</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Views/view_MakeAnOrder.php">MAKE AN ORDER</a>
This is the include of the pages:
<?php
include('../Common/Header.php');
include('../Common/NavigationBar.php');
?>
These are the file directories:
https://i.stack.imgur.com/p9dA7.png
https://i.stack.imgur.com/wrp5S.png
These are the URLs and before and after i get the error:
Website starts on the index page:
myphp/Ticototrading/index.php
When i click a link it redirects the user to:
myphp/Ticototrading/Views/view_BecomeCustomer.php
And then, when i click on the home link(or any navlink) on the navbar again i get the "Object not found" error and i noticed the problem lies with the file path that has changed to:
myphp/Ticototrading/Views/index.php
When I redirect to a different page, the current page adds its folder to the file path instead of going directly to the href="" given.
<li>SERVICES</li>
<li>ABOUT</li>
<li>CONTACT</li>
I'm using CodeIgniter and this code was in a different controller. suppose http://localhost/defctrl/function1
I want to return to my homepage "maine/home" in a specific div when you click on the list but the above code doesn't work. neither ../maine/home#services.
How can I solve this problem?
if it's on the same page you can use
<li><a href="#services"
if another page
<li><a href="<?php echo base_url() ?>{route or controller name}#services"
Make sure URL helper is loaded and site load with index.php
I am experiencing a very strange problem.
I have 3 pages :
home.php
forums.php
projects.php
Every page has a menu like this:
<ul>
<li><a href='http://www.mysite.com'>Homepage</a></li>
<li><a href='forums.php'></a>Forums</li>
<li><a href='projects.php'></a>Projects</li>
</ul>
When the user is logged in sessions are set up and in every page on top username is shown.
If I'm in Projects page and my username is on top as I am logged in and now I want to go to main page, when I cycle through projects and forums the username is on top and sessions are not lost. When I click Homepage it goes to main page sessions are lost and the username is lost on the top.
I think the problem is with the first link Homepage.
When I do it index.php everything works fine but with this http:// it is not working. Actually sessions are still there but not showing up.
UPDATE
I think I found the problem
I converted all menu links to full links with http not only php files like this
<ul>
<li><a href='http://www.mysite.com'>Homepage</a></li>
<li><a href='http://www.mysite.com/forums.php'></a>Forums</li>
<li><a href='http://www.mysite.com/projects.php'></a>Projects</li>
</ul>
And everything works fine.
I am curious and I want to expand my knowledge. If anyone knows why is this happening please let me know.
converted all menu links to full links
No
http://www.mysite.com is not a valid URL, some webservers will assume that the path is '/', some browser will assume the path is '/' but most browsers will send the URL as is, and the webserver will usually send a redirect back to the browser.
As long as the host is the same in all cases or omitted, then the code will behave as you expect - but you really should use proper URLs to avoid subtle semantic issues i.e.
<ul>
<li><a href='http://www.mysite.com/'>Homepage</a></li>
<li><a href='http://www.mysite.com/forums.php'></a>Forums</li>
<li><a href='http://www.mysite.com/projects.php'></a>Projects</li>
</ul>
or...
<ul>
<li><a href='/'>Homepage</a></li>
<li><a href='/forums.php'></a>Forums</li>
<li><a href='/projects.php'></a>Projects</li>
</ul>