I just started learning PHP, and I wanted to make a redirection to a new site. I want it to be somewhat like the location.href="http://example.com"
in Javascript, but I didn't find anything... Any ideas?
Asked
Active
Viewed 90 times
-3

Marvin Johanning
- 1
- 1
4 Answers
2
In PHP you have to set header
. Check Manual
header("Location:http://example.com");

Sadikhasan
- 18,365
- 21
- 80
- 122
1
Try this:
header("location: http://example.com");
exit();
exit()
is must, else the codes after header will be executed.

Vivek Pradhan
- 4,777
- 3
- 26
- 46

Sarath Mohan
- 157
- 1
- 6
-
`exit() is must`: just that it's not. So what if the remaining code is executed? It's not a must its just a precaution for lazy programmers. If the code was written well then a redirect would be made at the logical end of the code where there is no further processing left. – Hanky Panky Feb 18 '15 at 09:46
-
@Hanky, i think the termination of script execution & calling the destructors might be the enough reason for using the exit() after header() :) – Sarath Mohan Feb 18 '15 at 10:42
0
In the PHP code you have to set header like below
header("Location:http://example.com");
exit();
Or you can set like this
<?php
echo"<script>window.location='URL of your website'</script>";
?>

varad mayee
- 619
- 7
- 19
0
You can echo the HTML/HTTP redirection tag. Just paste the following
<?php
echo '<meta http-equiv="refresh" content="0; url=http://example.com/" />'
?>
Please escape the quotes and change the URL appropriately.
This should be the first line written to the browser or it may or may not work.
Repeat Using Javascript
<?php
echo '<script type='text/javascript''>window.location.href='example.com'</script>
?>
Please escape the quotes appropriately

Nithin Devang
- 69
- 1
- 8
Go to website
'; – Comum Feb 18 '15 at 09:10