PHP help

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
i've been working really hard on a new website and i've reached a pretty tough to resolve problem right about now:

the website structure is as follows:

- main.php (this file contains the site layout divs, including banners, navigation menus and login forms)

- when a user clicks on any link, I use html to send GET variables and reload main.php and include the corresponding html file into the content div, creating a smooth frame-style navigation

- i just realized, however, that I cannot link from one page to another directly because I can't send anymore headers as I've outputted information in main in order to construct the site's dynamic layout (multiple languages for menus)

as far as normal text links go it's fine, i can just use html linking, but for my login page...

when the user submits the form I run a script and validate the entires, check for duplicates in the database, etc and then if everything is ok I add a new entry. after adding the user I would like to send the user to a welcome page but I can't send anymore headers... i don't send any in the script but since it's running from a file included in main.php it doesn't seem to work...

can anyone help me???? thanks! :)
 

clamum

Lifer
Feb 13, 2003
26,256
406
126
Have the form submit to a different .php file, say validate.php. Then do your validation and adding in there, then redirect to the page afterwards.
 

jjones

Lifer
Oct 9, 2001
15,424
2
0
Use output buffering. Since everything is buffered before output, you can process whatever you need to, and then use the header function to redirect if desired.
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
use AJAX....submit the form using Javascript (will have to parse all the field for the AJAX request...send back a err/ok depending on validation...if validation okay the document.location=welcome file
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
Originally posted by: clamum
Have the form submit to a different .php file, say validate.php. Then do your validation and adding in there, then redirect to the page afterwards.

thanks, I did that and managed to tie everything together pretty nicely!

Originally posted by: jjones
Use output buffering. Since everything is buffered before output, you can process whatever you need to, and then use the header function to redirect if desired.

as you very well know I'm still a bit of a newbie/intermediate php guy (yeah, that's right I just upped my rank to intermediate! :p) and I'm not very confident with output buffering yet, but I'll read into it a little more as I have a feeling I will have to use this sooner or later!

Originally posted by: Drakkon
use AJAX....submit the form using Javascript (will have to parse all the field for the AJAX request...send back a err/ok depending on validation...if validation okay the document.location=welcome file

unfortunately I haven't gotten around to studying AJAX yet... although it's on my priority list, hand in hand with XML and javascript! :)
 

tersome

Senior member
Jul 8, 2006
250
0
0
Have you tried using superglobals, say "main.php?page=#"? Would that solve the header problem?
 

jjones

Lifer
Oct 9, 2001
15,424
2
0
Originally posted by: franguinho
Originally posted by: jjones
Use output buffering. Since everything is buffered before output, you can process whatever you need to, and then use the header function to redirect if desired.

as you very well know I'm still a bit of a newbie/intermediate php guy (yeah, that's right I just upped my rank to intermediate! :p) and I'm not very confident with output buffering yet, but I'll read into it a little more as I have a feeling I will have to use this sooner or later!
Hey, at least you got it to work as needed. That's what counts. :)
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
Originally posted by: jjones
Originally posted by: franguinho
Originally posted by: jjones
Use output buffering. Since everything is buffered before output, you can process whatever you need to, and then use the header function to redirect if desired.

as you very well know I'm still a bit of a newbie/intermediate php guy (yeah, that's right I just upped my rank to intermediate! :p) and I'm not very confident with output buffering yet, but I'll read into it a little more as I have a feeling I will have to use this sooner or later!
Hey, at least you got it to work as needed. That's what counts. :)

true enough! :)

although this is a professional website that i'm selling to a company they've given me very good deadlines (by May 30th) so this has really served as a learning experience more than anything! :)

and to boot i rewrote most of my code using OOP so I have a couple classes I can use for other projects too! man i love programming! :D

jjones thx for showing up to all my PHP threads I really appreaciate it! :)

Originally posted by: tersome
Have you tried using superglobals, say "main.php?page=#"? Would that solve the header problem?

I'm using GET, POST and SESSION superglobals throughout the site! the only kind of global ive been avoiding are $GLOBALS for good practice, altough sooner or later I might have to use them.