Help with PHP Page Coding

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
aodat2
Forum Newbie
Posts: 12
Joined: Wed Aug 13, 2008 7:19 am

Help with PHP Page Coding

Post by aodat2 »

I have something which I find quite interesting. Till now I have yet to find any answers or anything which is close or even resembles what I really need.

This is basically what I have...

Page 1 --> Page 2 --> Page 3 --> Page 4

My problem is how do I make it in such a way that someone needs to actually go to Page 1 before going to Page 2, 3 or 4? Is there a way to actually do this? I would appericiate it if someone could help tell me what I could do to get this going.

Thank you very much.
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Help with PHP Page Coding

Post by desmi »

Well basicly you can do it with simple cookie..

on page 1, set cookie
on page 2,3 and 4, check for that cookie, if found, let in, if not, redirect to page1
aodat2
Forum Newbie
Posts: 12
Joined: Wed Aug 13, 2008 7:19 am

Re: Help with PHP Page Coding

Post by aodat2 »

That's my basic problem...

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by... (the session script on the session_start() function).

The funniest thing is that my entire page has only 2 JavaScript and 1 Form in HTML. No sessions or anything or even headers at all. Not even sure why it's giving me that problem.
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Help with PHP Page Coding

Post by desmi »

Please post your code.
Geteburg
Forum Commoner
Posts: 25
Joined: Tue Aug 12, 2008 1:57 pm

Re: Help with PHP Page Coding

Post by Geteburg »

aodat2 wrote: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by... (the session script on the session_start() function).
That Warning is that you output something before you call session_start() function. You MUST start session BEFORE any output!! So basically, just put it at the top of the file, first line or so :) That should fix this Warning.

As for the thing you want, use SESSION. No need for cookie really.

AKA if no session is set, go to page 1 no matter which page was called. When user click "page 2" from "page 1", set session to something like $_SESSION['page'] = 2, and so on..
aodat2
Forum Newbie
Posts: 12
Joined: Wed Aug 13, 2008 7:19 am

Re: Help with PHP Page Coding

Post by aodat2 »

Geteburg wrote:
aodat2 wrote: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by... (the session script on the session_start() function).
That Warning is that you output something before you call session_start() function. You MUST start session BEFORE any output!! So basically, just put it at the top of the file, first line or so :) That should fix this Warning.

As for the thing you want, use SESSION. No need for cookie really.

AKA if no session is set, go to page 1 no matter which page was called. When user click "page 2" from "page 1", set session to something like $_SESSION['page'] = 2, and so on..
Thanks so much for the help. This might be a stupid question but I'm a total noob and I'm going to ask it anyways. What am I suppose to put in Page 2, 3, 4 and etc?

Hope you could help on this.

By the way, I've got the session thingy down, just don't really know how to use it. Hahaha... gosh, I'm such a noob.
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Help with PHP Page Coding

Post by desmi »

http://www.php.net/session

Read this, it'll light things up..

And you need to check if there's session on pages 2-4

eg.

Code: Select all

if isset($_SESSION['yoursession']) { your code here }
Post Reply