FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Form & Redirect





tomahawk19
crap, I usually don't have problems with PHP, but now I am.
Code:
         <?php
            if ($_POST['form_submitted2']) {
               $myUrl = $_POST['word_letter'];
               header("location:http://tcomputers.frih.net/" + $myURL);
            } else {
            echo "<div align=center>Select Newsletter You Wish To Download</div>";
            }
            ?>


The form has a list of files to download, then I'm trying to have it redirect after I submit a form to download the actual file. It should redirect to a .doc file, but since I already have the header filled out, it won't let me use header. Does anyone know of a different way to redirect? Or anything that might help?
shamil
Yes you cannot use redirect after headers already sent. If you want to redirect just redirect why send headers?
sonam
I think problem is in this line:

Code:
header("location:http://tcomputers.frih.net/" + $myURL);


try to change + in .

Code:
header("location:http://tcomputers.frih.net/" . $myURL);


or just

Code:
header("location:http://tcomputers.frih.net/$myURL");


Sonam
chris20
Yeah, your header is already sent so you can't do a redirection that way, try echoing the following though, it should redirect you without any problem...

<meta http-equiv="Refresh" content="4;url=http://www.domain.com">

Where 4 is the number of seconds to wait before redirecting. You can put it anywhere you want on the page so don't worry about sticking it in the <head> section if you can't.

Hope this helps.
tomahawk19
Well none of those worked, I even modified the meta tag, but it still did not want to work. Any other ideas?
hexkid
tomahawk19 wrote:
I even modified the meta tag, but it still did not want to work.

What meta tag? There is no meta tag in the code you posted!

Let me guess ...
You have something like this
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
  <title>test</title>
</head>
<body>
<?php
if (rand(0, 1)) {
  header('Location: http://example.com/');
} else {
  echo "<div>newsletter</div>";
}
?>


Just move the php to before the <!DOCTYPE
Code:
<?php
if (rand(0, 1)) {
  header('Location: http://example.com/');
} else {
  $contents = "<div>newsletter</div>"; // no echo here
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
  <title>test</title>
</head>
<body>
<?php
  echo $contents;
?>
tomahawk19
actually no, I don't have my code like that. I have something like this...

Code:
<?php include("header.php"); ?>
Then the information for my page goes here
<?php include("footer.php"); ?>


I'll post it all soon...I just have to get back to my computer...
hexkid
Try this then ... (I don't like it!!)

Code:
<?php ob_start(); ?>

<?php include("header.php"); ?>
Then the information for my page goes here
<?php include("footer.php"); ?>

<?php ob_end_flush(); ?>


ob_start() will capture all output from the script (except for headers) instead of sending it to the browser. If your "Then the information for my page goes here" does a redirect (followed by an exit()) the ob_end_flush() will not get called, otherwise all the contents captured are sent to the browser then.
Related topics
.co.nr is back up and accepting registration
Free Domain & Redirect Services
Site about RO
formularios y correo-e, !ayuda¡
Duke Lacrosse Q/A
What's your favourite car from BMW? and why?
Need a simple Contact form
Znudzil Ci sie Windows? Linux z dostawa do domu za DARMO!
Favourite albums?
A question for all you monotheists.
curves?
please please beta test it (PHP coders)
How to automate 3rd party forms and upload data?
Placement of Brackets in php code
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.