Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the URL through PHP

Tags:

url

php

I want to change the URL through PHP.

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

I want the same thing but in PHP. How can I do it?

like image 849
Nitz Avatar asked May 04 '10 09:05

Nitz


People also ask

How can I change the current URL in PHP?

php if (! $_GET["name"] && $_GET["id"]) { // perform MySQL query to get name based on id header("Location: http://www.something.org/zzz"); die(); // stop execution of this page } // if we got here, $_GET["name"] is set, so do whatever this script is supposed to do. ?> NOTE: The above .

How add http URL in PHP?

<? php if (! preg_match("/^(http|ftp):/", $_POST['url'])) { $_POST['url'] = 'http://'.$_POST['url']; } $url = $_POST['url']; ?> This code will add http:// to the URL if it's not there.

How do I get the URL of a PHP file?

Answer: Use the PHP $_SERVER Superglobal Variable You can use the $_SERVER built-in variable to get the current page URL in PHP. The $_SERVER is a superglobal variable, which means it is always available in all scopes.


2 Answers

You can use the header function for that:

header("LOCATION: http://www.something.com");
like image 182
Sarfraz Avatar answered Sep 18 '22 08:09

Sarfraz


You could use the header() command:

<?php
  header("Location: http://www.example.com/");
?>
like image 32
richsage Avatar answered Sep 20 '22 08:09

richsage