I have Three different buttons.
First Button should redirect to the Google.com, that too using Header() method.
Second Butto开发者_C百科n should redirect to stackoverfkow.com using other then Header() method.
And finally Third button should redirect to the page which is in my local machine (Path of that file is D:\Work space For Practice\Redirection\HomePage.php).
Please can any one help me. Thanks in advance
you can also write like this.. you should 1st give a name off button like button.html:
<html>
<head>
<title>buttons</title>
</head>
<body>
<input type="button" onclick="document.location='redirector.php?q=1'" name='home' />
<input type="button" onclick="document.location='redirector.php?q=2'" name='ABC' />
<input type="button" onclick="document.location='redirector.php?q=3'" name='XYZ' />
</body>
</html>
and your php file is
if(isset($_POST['Home']))
{?>
<script>window.location = 'http://google.com';</script>
<?php
}
if(isset($_POST['ABC']))
{?>
<script>window.location = 'http://stackoverflow.com';</script>
<?php
}
button.html:
<html>
<head>
<title>buttons</title>
</head>
<body>
<input type="button" onclick="document.location='redirector.php?q=1'" />
<input type="button" onclick="document.location='redirector.php?q=2'" />
<input type="button" onclick="document.location='redirector.php?q=3'" />
</body>
</html>
redirector.php:
<?php
if($_GET['q'] == 1) {
header('LOCATION: http://google.com');
} else if ($_GET['q'] == 2) {
header('LOCATION: http://stackoverflow.com');
} else {
header('LOCATION: homepage.php');
}
?>
You cant' use header, because it will call your php file from your browser, and not interpret it.
Do you use a local web server? Then redirect to (for example) "http://localhost/HomePage.php" with Header() method.
Why you are using header() method for that? you can use javascript function.
i.e `getRedirect(this.id)`
and put it onclick
event of your buttons.
where you should check button name or ID..
function getRedirect(thisid){
if(thidid == 'first'){
window.location = 'www.google.com';
}else if(thidid == 'second'){
window.location = 'www.stackoverflow.com';
}else{
window.location = 'localpath';
}
}
This may be what u needed...
Thanks.
you php function may look like this.
<?php
function getredirect(btn_value){
if(btn_value == 'first'){?>
<script>window.location = 'www.google.com';</script>
<?php }else if(btn_value == 'second'){?>
<script>window.location = 'www.stackoverflow.com';</script>
<?php }else{ ?>
<script>window.location = 'your local path';</script>
<?php } ?>
}
?>
Thanks..
精彩评论