i'm a newbie in php, and i know this question maybe silly :(
i tried to create a php file that will redirect to yahoo.com.
i have searched in google, and i found that the code should be

<?php
    header('Location:http://www.yahoo.com
?>

but i found that it didn't work.
anyone has clue about this?
does the version of php affect it?

Recommended Answers

All 30 Replies

Does it do anything?

Do you get a blank screen, an error?

Member Avatar for diafol

This may sound stupid, but:
Do you have php installed?

Does it do anything?

Do you get a blank screen, an error?

yes, i only get blank page and the active page is still the php file that contains that code. do you have any clue about this? thanks for your response.

This may sound stupid, but:
Do you have php installed?

yes, i have installed wamp server, included apache, php, and mysql in it. the version of the php is 5.2.5, so i don't think that it's because the version of the php. thanks for your response.

yes, i have installed wamp server, included apache, php, and mysql in it. the version of the php is 5.2.5, so i don't think that it's because the version of the php. thanks for your response.

What browser are you using (type & version)?

Can you please right click on the page, choose "view source" and paste the contents here?

here is the code

<?
header("location:index.html");
?>

and the address is still at "file:///C:/Program%20Files/wamp/www/Projek%20SBD/Projek/logout.php" (NB : logout.php is the name of the file that contains that code)

i'm using mozilla firefox, version 3.0.15.
thanks for your response.

here is the code

<?
header("location:index.html");
?>

and the address is still at "file:///C:/Program%20Files/wamp/www/Projek%20SBD/Projek/logout.php" (NB : logout.php is the name of the file that contains that code)

i'm using mozilla firefox, version 3.0.15.
thanks for your response.

It seems like you're trying to directly open the file in the browser instead of using the apache web server installed on your computer for accessing the file.
your URL should be something like:

http://localhost/Projek%20SBD/Projek/logout.php

If you open the file itself, the PHP code doesn't run. The browser simply displays the content of the file...

Member Avatar for diafol

Do any of your php pages show as "proper webpages" in FF? It's just possibel that the Apache webserver, although installed, is not on. I am not familiar with WAMP (I use XAMPP), but I assume it has a control panel - check to see if Apache is on.

In addition, perhaps it would be useful to check your hosts and vhosts files - usually something like this):

C:\Windows\System32\drivers\etc\hosts
C:\xampp\apache\conf\extra\httpd-vhosts.conf (yours will probably be under some sort of wamp directory).

The hosts file (note no file extension) should contain something like:

127.0.0.1 localhost
::1 localhost

The other file should contain something like:

NameVirtualHost 127.0.0.1

These files are where you'd add your virtual local sites


//EDIT

Just looked over the first couple of posts again:

header('Location:http://www.yahoo.com');

If the above won't work, it's not because you can't find the localhost through the header command, it's probably because php won't run at all in this location (localhost).

Can you run a simple

echo "hello world!";

page?

make a file called phpinfo.php with the folowing code:

<?php
phpinfo();
?>

Now if PHP is installed & working correctly, you should see a load of data & variables in a table with a purple background. If not, something is wrong with your PHP/Apache install.

Joshhh

Try this

<?php
header("Location:yahoo.com");
?>

it can be possible that short tags are off in php.ini. So Try once the above code.!!

commented: Read the original post +0

Lets Try This ...
1. "L" MUST BE CAPITAL
2. Provide a space as i mentioned below ,this will be useful for IE

1.
<?
header("Location: index.html");
?>

@ardav : i have installed xampp now, thought that something's wrong with wamp. but everything is still the same. i have checked those files, the one in win32 is okay, but i can't find "NameVirtualHost 127.0.0.1" in httpd-vhosts.conf. what should i do? anyway, i installed xampp in c/program files/xampp not in c/xampp, is it okay? and i can run simple php file like that hello world.

@rokape : yes, it works. seems nothing's wrong with my php installed here. thanks for your response.

@sam023, manus : they all don't work, still leads to a blank page :(

@foxwizzy : you mean i must write it like this?

<?
echo "<meta http-equiv="refresh" content="1; URL=http://yahoo.com">";
?>

but i only get this in my page :(
"; ?>

@foxwizzy : oh sorry, i wrote it in wrong way. yeah it works. but i have to add some php code in this file. can i do this, create this file as html file, and add <?php code blablabla ?> inside it?

You only get that because you used a " inside your echo string not ' or an escaped /".

This concludes that your install isnt working because otherwise this would error, unexpected t var etc.

Member Avatar for diafol

I shouldn't have thought it would make much difference, but have you included an

exit;

on the next line after the header() statement?

In addition, make sure there is no html output including any white space before the header().

you mean this?

<?
session_destroy();
header("location:index.html");
exit;
?>

i have tried that and nothing happens again :(

guys, today i tried to install the same wamp in other PC. and surprisingly, it works there!! guess the wrong thing is my PC now, or maybe the setting of the apache or php. do you have any ideas?

guys, today i tried to install the same wamp in other PC. and surprisingly, it works there!! guess the wrong thing is my PC now, or maybe the setting of the apache or php. do you have any ideas?

Try uninstalling WAMPServer and reinstalling it. Sometimes a bad download leaves PHP handicapped. Also check if the PHP version is the newest one.

Also, even if you have the server online you might have not started the services properly. Check all that just to make sure. Other than that, your code works fine (if you have also followed guidelines by the previous posters as well).

guys, i know this sounds strange. but that header finally works after i added php in <?php
haha, i don't know that the word "php" will affect that much.
anyway, thx so much guys. in return, i would like to help you if you have some problem with cpp, i love programming in cpp :)
once again, thanks so much all.

Member Avatar for diafol

Try this

<?php
header("Location:yahoo.com");
?>

it can be possible that short tags are off in php.ini. So Try once the above code.!!

Yep, sam023 did mention it.

yes, i didn't notice that :(
a huge thanks for sam023 for the solution and ardav for helping me with your ideas :)

Member Avatar for diafol

@rokape - it's SOLVED!!

I missed that bit :|

Is that code you pasted the entire PHP program / script? What you are doing needs to be the first thing sent to the browser, for instance.

great finally u got the output..!!!

In WAMP. 'short_open_tag' is off by default..!!

but you can ON it by going in php.ini and search for word 'short_open_tag'. make it ON.. and restart the wamp server..!!

then you can use short tags..!! means u can use <? ?> instead of <?php ?>


Best of Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.