Mishigen
Mishigen

Reputation: 1261

open url through header in php

I have a .php file in which i have a added a simple code:

<?php
header("Location:http//www.google.com");
?>

when i run this code, then instead of opening google.com it opens a download file, which is the same as my php file.

Upvotes: 1

Views: 3520

Answers (5)

Matt Mitchell
Matt Mitchell

Reputation: 41833

Are you running on a server? If not, download XAMPP and put your PHP file in the htdocs folder. Then click xampp_start.exe in the main folder. Then go to localhost/youphpfile.php in your web browser.

Upvotes: 0

JAL
JAL

Reputation: 21563

You need a space after Location: for the redirect to work properly. Also, make sure you have the colon after http.

Try

header("Location: http://www.google.com"); 

Upvotes: 3

Byron Whitlock
Byron Whitlock

Reputation: 53901

You have to make sure your server is setup to parse php files.

Something like this in apache:

AddHandler php5 .php .php5

edit

You would add this in the apache configuration file. httpd.conf

Take a look at this article. It walks you step by step on how to do this. I am assuming you are using windows.

Upvotes: 5

Babiker
Babiker

Reputation: 18798

You need to install/enable you server's php module, or if you are in windows, download WampServer and install it.

Upvotes: 2

houbysoft
houbysoft

Reputation: 33412

Surely you meant

<?php header("Location: http://www.google.com"); ?>

?

Upvotes: 0

Related Questions