Page 1 of 1
What is wrong?
Posted: Sun Mar 02, 2008 8:39 pm
by cmarc
The frustrations are piling up for an absolute newbie...
I can't even get simple things to work like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>justatitle.dk</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
</head>
<body>
<?
header ("Location:
http://www.justawebsite.com/folder/main.php");
exit;
?>
</body>
</html>
Isn't this supposed to automacially send me on to
http://www.justawebsite.com/folder/main.php when I visit a page with the code above?!
What is wrong?
Thank you.
- cmarc
Re: What is wrong?
Posted: Sun Mar 02, 2008 8:46 pm
by Sekka
Headers can only be sent
before anything what so ever is sent to the user.
If you are wanting to redirect someone, all you need to do is,
Code: Select all
<?php
header ("Location: http://www.justawebsite.com/folder/main.php");
exit();
?>
Hope this helps!
Re: What is wrong?
Posted: Sun Mar 02, 2008 9:02 pm
by cmarc
Okay, maybe that's my problem then.
Is there a way to redirect in pure html-code then?
Thank you.
- cmarc
Re: What is wrong?
Posted: Sun Mar 02, 2008 9:57 pm
by cmarc
I'm now able to redirect using PHP just by making sure that nothing else comes first, then it works.
But this is my exact problem as I wanted to redirect from a page that specifies assorted variables to pass their values on to the main page, where they will be used only once.
Is there a way to do this?
- cmarc
Re: What is wrong?
Posted: Sun Mar 02, 2008 10:28 pm
by devendra-m
Is there a way to redirect in pure html-code then?
Code: Select all
<meta http-equiv="refresh" content="0;URL=test.php">
Re: What is wrong?
Posted: Mon Mar 03, 2008 8:58 am
by Sekka
cmarc wrote:I'm now able to redirect using PHP just by making sure that nothing else comes first, then it works.
But this is my exact problem as I wanted to redirect from a page that specifies assorted variables to pass their values on to the main page, where they will be used only once.
Is there a way to do this?
- cmarc
You can pass variables from page to page in a number of ways. The two most popular are,
Sessions
Page 1:
Code: Select all
session_start();
$_SESSION['var1'] = "something";
header ("Location: http://www.somewhere.com/somepage.php");
exit ();
Page 2:
Code: Select all
session_start();
if (isset ($_SESSION['var1'])) {
$var1 = $_SESSION['var1'];
// Do something
}
URL Query Strings
Place the variables on the end of the URL link to the next page, e.g.
Page 1:
Code: Select all
header ("Location: http://www.somewhere.com/somepage.php?var1=something");
exit ();
Page 2:
Code: Select all
if (isset ($_GET['var1'])) {
$var1 = $_GET['var1'];
// Do something
}
devendra-m wrote:Code: Select all
<meta http-equiv="refresh" content="0;URL=test.php">
That method doesn't always work and is disliked by many search engines. You can get black listed for using them. I would recommend redirecting in PHP instead.