1

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.

<a href="<?php echo $ROOT_URL; ?>admin/admindashboard.php">Home</a>
<ul class="dropdown-menu">
      <li><a href="addproduct.php">Add Product</a></li>
      <li><a href="product/viewproduct.php">View Product</a></li>
      <li><a href="removedproduct.php">Removed Product</a></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??

  • Possible duplicate of [HREF="" automatically adds to current page URL (in PHP). Can't figure it out](https://stackoverflow.com/questions/8764288/href-automatically-adds-to-current-page-url-in-php-cant-figure-it-out) – Dawid Zbiński Jul 29 '18 at 09:19

2 Answers2

0

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/';
piyush
  • 655
  • 4
  • 11
0

If the link points to a local location, you can just use / as root.

This, for examples will work:

<a href="/office/admin/admindashboard.php">Home</a>

If $ROOT_URL is dynamic and you want to include the variable, define it as:

$ROOT_URL = '/office/';

Then you can do:

<a href="<?php echo $ROOT_URL; ?>admin/admindashboard.php">Home</a>

Also, the links in the list

<ul class="dropdown-menu">
  <li><a href="addproduct.php">Add Product</a></li>
  <li><a href="product/viewproduct.php">View Product</a></li>
  <li><a href="removedproduct.php">Removed Product</a></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.

Robert
  • 5,703
  • 2
  • 31
  • 32