Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirection

Status
Not open for further replies.

stasJohn

Programmer
Joined
May 6, 2004
Messages
155
Location
US
As I understand, using the header() command can only be used before any output is sent to the browser. I'm having an issue with dreamweaver (using templates) where its not allowing me to insert code above the <html> start tag. To get around that, I stick the code in the <head></head> section. But, there redirection using header stops working. Is there another alternative to header().


I thought about just putting the php that I want to place above the <html> start tag in its own script file, so when the php code is done it just calls the page I was trying to add the code to. How do I easily pass, say an array of values, between scripts?

Thanks in advance.
 
Here's a hint:
You need not start the page with the HTML template. WHy don't you include the HTML with an include() statement and write the code that you want executed before that?
Code:
<?php
# whatever
if (my...){
   # redirect
   header(...);
}
# show page of not redirected
include("template.html");
?>
This way you have no trouble with Dreamweaver and you can have your code first.
 
well, first of all you are right, header() must be used before any output... if dreamweaver doesn't let you add stuff in the right begin of the file, just save it and edit using notepad, adding the header command in the beginning.

you can use an javascript alternative, just echo "<script>window.location='blabla.php'</script>" (inside <body> only)

about calling scripts, you can use include() command.

and about passing values between scripts you just need to have the variable in one script, and when that script is called (using include()) all the variables remain intact, and can be used by the *calling* script.

IF you need to pass vars between webpages, say from page1.php to page2.php, you have to use a proper link, on page1.php you'll have something like '<a href="page2.php?var1=foo&var2=bar">page2</a>'.
otherwise you must use sessions.

jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
hey thanks for the suggestions...

the code...
<?php
# whatever
if (my...){
# redirect
header(...);
}
# show page of not redirected
include("template.html");
?>

works like a charm. Not entirely happy with the fact that it creates 2 files when I should of only had to use one, but for now, it'll do.

thanks again.

if anyone wants to post any other suggestions, I'd love to look at them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top