I have a page index.php
of my website abc.com
having some internal links e.g. contactus, aboutus etc on it.
Kindly guide me how is it possible that when someone clicks on a link (say contactus) of the page index.php
, then request should go to index.php
. But index.php
should reload itself with the new url i.e. abc.com/contactus
.
Hope It Works As You Want
on link menu declare links like
<a href="index.php?link=contact_us">Contact Us</a>
when someone click on the link then
on index.php
if(isset($_GET['link']))
{
$link =$_GET['link'];
if($link == 'contact_us')
{
header("location:contact_us.php");
}
}
//Contact us link
<a href="index.php?redirect_url=contact_us">Contact Us</a>
//Javascript code
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var redirect_url = getParameterByName('redirect_url');
//will redirect to contact us page after 3 seconds. You can change it as per your requirement
if(redirect_url){
setTimeout(function(){ window.location.href = redirect_url; }, 3000);
}
<?php
/*we will use this this function ob_start() in the first of php page to redirect the users after your submit data
ob -> output buffering */
ob_start();
?>
<!--for example -->
<?php
/*write this function in the first of php page*/
ob_start();
?>
<?php
/*write your Query here after you write your query you will write the page that you will direct the users for example */
header('location:index.php');
} ?>