Changing URLs through PHP

I want to change the URL via PHP.

Something like window.location.href = "http://www.something.com" in JavaScript.

I want the same thing, but in PHP. How can i do this?

+7
url php
source share
4 answers

To do this, you can use the header function:

 header("LOCATION: http://www.something.com"); 
+18
source share

You can use the header () command:

 <?php header("Location: http://www.example.com/"); ?> 
+2
source share
 <?php header('Location: http://www.example.com/'); ?> 

Make sure there is nothing above the output line, otherwise it will fail.

+1
source share

You can use ob_start along with the header to prevent redirection errors:

 <?php ob_start(); // Starts Output Buffering header(/*Your redirection location*/); // Redirects user to given location. ?> 
0
source share

All Articles