i want to call a php function header('Location:http://xx.yy.zz/somthing') inside a javascript function,Like given below.
<?php
<script>
function mUp(obj)
{
//here i want call the header function
}
</scipt>
//some code
?>
Pls help..
Thats not how it works.
Use:
window.location = "http://xx.yy.zz/somthing";
You can't execute a PHP header function inside Javascript.
Javascript runs inside the browser, While PHP runs on your server.
do something like
window.location.href = "http://xx.yy.zz/somthing";
This is something for JavaScript, not for PHP:
<script>
function mUp(obj)
{
document.location.href = 'http://www.example.com/';
}
</script>
I guess you want to do a redirect, it would be good to redirect through javascript itself , if you want to write PHP code inside, just use PHP tags in between and write the code..or echo the javascript code and write PHP code.
The code similar to PHP's header()
location
function:
header('Location:http://xx.yy.zz/somthing');
In javascript is,
location.href = "http://xx.yy.zz/somthing";
Both does the same redirect for the users, but the former one returns a HTTP Status of 301.
Why don't you use directly the javascript version?
Have a look to window.location object.
why PHP function for redirecting ? If you want to redirect simply
document.location.href='http://xx.yy.zz/somthing';
There is no need to put php code. .Just try this...
<script>
function mUp(obj)
{
window.location="http://xx.yy.zz/somthing";
}
</scipt>
By now you probably have noticed that If you put a php header redirect in after already sending html/any text to the client's browser, you get an error; this is because the header() function tells the server to cancel the output from the current page and redirect to another page at the server-side. so either you should find a way to execute that header function before printing any html/js to the broswer, or you could do a javascript redirect:
<script type="text/JavaScript">
window.location.href="http://xx.yy.zz/somthing";
</script>
please comment if this isn't clear enough
Hi the following link may help you
Try this
header('Location:yourpage.php');