Page 1 of 1

Help with PHP Page Coding

Posted: Thu Aug 14, 2008 9:19 am
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.

Re: Help with PHP Page Coding

Posted: Thu Aug 14, 2008 9:41 am
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

Re: Help with PHP Page Coding

Posted: Thu Aug 14, 2008 9:46 am
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.

Re: Help with PHP Page Coding

Posted: Thu Aug 14, 2008 9:55 am
by desmi
Please post your code.

Re: Help with PHP Page Coding

Posted: Thu Aug 14, 2008 10:04 am
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..

Re: Help with PHP Page Coding

Posted: Thu Aug 14, 2008 10:25 am
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.

Re: Help with PHP Page Coding

Posted: Thu Aug 14, 2008 10:37 am
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 }