concerning States

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
queirozf
Forum Newbie
Posts: 2
Joined: Tue Jun 08, 2010 3:51 pm

concerning States

Post by queirozf »

hello. I hope someone can help me with this.

i have this page, called file_pool.php, which is where logged users can access uploaded files by other members.

However, the user should only be able to view the files ONCE he/she has been found to be in the DB.

SO it goes like this

*if the user isnt logged in yet*

Code: Select all

if (!isset($_SESSION["user"])) { #show html forms and etc so the user can log in}
but if the user IS already logged in (i.e. $_SESSION["user"] is SET) then i want to show then something else...

Code: Select all

else{ #show the files the user can download}
But the catch is: say a user isn't logged in yet. So he goes, fills out the html forms and hits "Submit". Suppose his username AND password match.
I would like php to, once the user has been authenticated, make some sort of refresh on the page, so it now shows the members-only area, namely the files. But without me having to hit refresh on my browser.

I looked into some answers for this and came up with the header() function, but im not sure how i should use it, or maybe is there some other way?

thanks in advance hope you understood
User avatar
phdatabase
Forum Commoner
Posts: 83
Joined: Fri May 28, 2010 10:02 am
Location: Fort Myers, FL

Re: concerning States

Post by phdatabase »

If you submit a form the page will automatically refresh, or at least will have that effect, to make the form submission available to the page.
queirozf
Forum Newbie
Posts: 2
Joined: Tue Jun 08, 2010 3:51 pm

Re: concerning States

Post by queirozf »

it still doesnt.... As you've seen, my .php file is split into two cases: #1 if the user is not logged in, #2 if the user is logged in (i.e. Session Variables have been set)

what i would LIKE to happen is:

step1: user comes, isnt logged in (username and password forms are visible)
step2: user fills in forms, hits submit
step3: forms disappear, member-only area is shown.

i read something that made me think this would fall under the "one component querying" umbrella but it doent help me much.

thank you
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: concerning States

Post by John Cartwright »

Generally, you want to put all your processing code prior to outputting any HTML. Therefore, on the request that authenticates them, further on in the code when you output the member section or login, you have the correct info to display.
Post Reply