tags:

views:

119

answers:

6

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.

+2  A: 

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

Babiker
please be more clear.i m not able to understand you
sumit
+5  A: 

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.

Byron Whitlock
where to do this
sumit
+3  A: 

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"); 
Alex JL
A space after the colon is not required. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
Gumbo
space after colon is not working
sumit
@Gumbo While the spec may say that, as we know one can't trust that all browsers and proxy servers reliably implement the spec. I don't recall the details at the moment, but I have had issues with that in the past.
Alex JL
+1  A: 

Surely you meant

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

?

houbysoft
yea i m doing the same but its not opening the google pagerather a downloading link
sumit
+2  A: 

The fact your server is sending you the file for download can have the meaning of the PHP not being enabled within, you have posted too little information for us to know what the real problems is.

The most common way to know the problem is by looking at a file that saves all the errors when you try to access your file, try looking into your log folder for a error_log file.

Is this a home server that you are trying to run your code with ? if so what are you using as a server ? apache, is php instelled and configured ? please provide as much information as you can, if you are hosting your site else where does your host have a Panel with errors log or can you see them on the ftp ?

Prix
A: 

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.

Graphain