Forum Moderators: coopster

Message Too Old, No Replies

session

         

Naghmeh

12:31 pm on Apr 11, 2003 (gmt 0)

10+ Year Member



hi
first of all i have to say that i am some how new at php and when i am using session_start() in my script in IE will be written this
Warning: Cannot send session cookie - headers already sent
i dont know why , i have not used session before, and the funniest thing is that at first it works but when i started to use variables in my script it began to warns!

any suggestion is appreciable
regards,
naghmeh

jpjones

12:35 pm on Apr 11, 2003 (gmt 0)

10+ Year Member



You need to place the session_start() command before any other output on your page.
To guarantee this - try having it as the first line on your page.
e.g.
<?
session_start();

// other php stuff here
?>
<html>
etc...

Naghmeh

4:06 am on Apr 12, 2003 (gmt 0)

10+ Year Member



hi
thank you for your reply,
i have writen my session_start() just the place you have mentioned, but as i said it did not work,
i thought maybe the problem is with my php.ini but i check it out with a PHP book but it was just like what was written in the book.

regards,
naghmeh

jatar_k

4:17 am on Apr 12, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Naghmeh,

As is noted in the php manual for session_start() [php.net]

you must call session_start() before anything is output to the browser.

That error means exactly that, some data was outputted before you call session_start. Take a look at what is going on before your session_start. Something before it is sending output and causing the error.

Naghmeh

5:24 am on Apr 12, 2003 (gmt 0)

10+ Year Member



Thank you,
ok,let me describe my problem more, maybe it helps:
i use odbc to be connected to my db which is in access , when i select my recrods there are more than 50 and i want to break them into pages so in the main php script i wrote down session_start(); and then i wrote my script and have some outputs(ofcourse) and then i want to have a link to my next page ,so in the new script ,again i wrote
session_start();
to take the variables and my new script to get next records,am i wrong?

Regards,
naghmeh

jatar_k

5:54 am on Apr 12, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry Naghmeh, I don't really understand what you mean hear

and then i want to have a link to my next page ,so in the new script ,again i wrote
session_start();
to take the variables and my new script to get next records,am i wrong?

maybe a snippet of code? Is the error only when you go to the second page, every page or only the first page?

Naghmeh

2:15 pm on Apr 12, 2003 (gmt 0)

10+ Year Member



i am sorry too,maybe i say it bad,i'll try again:

for example when i show 20 of my records in a page, i want to show next 20 records in another page so i have to put a link on my page to show next 20 records, now for the first page i have to write my queries (but i think i dont have to write my queries again )so i can have a new script which takes some variables and shows next records.

i wish it is clear enough.
thank you
Naghmeh

Naghmeh

3:51 am on Apr 13, 2003 (gmt 0)

10+ Year Member



hi

From your advise i have looked up and found out that i have to use session_unset(); to release my variables ;
but when i use that, it just show one of my variabls and the others the same error.

about your Q that you asked if this problem is just for this page,this is the first page that i am writing with sessions.

regards,
naghmeh

jatar_k

6:05 pm on Apr 13, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So, if I understand correctly, you want to show 20 results on the first page and then the next 20 on the next page etc.

The way I do this is to pass an offset to the new page and then include that offset in your query to get the proper result set.

There are a bunch of different methods to do the multi page list. Two possibilities are the "next page - previous page setup". For this one you need to pass an offset, or first record, value.

ie on the first page we would show results 1-20 therefore the previous page would be disabled and the next page would have an offset of 21. The next page shows 21-40 the previous offset is 1 and the next offset would be 41. I figure you get my drift.

The second way is to list the page numbers. In this case we have 50 results and 20 per page. We would need to do a select and then count the total results and divide by the number of records per page (20).

Then we put each page number in a list and include the starting record offset in the link. ie page1=1, page2=21, page3=41.

So you may already understand this and this may be the method you are already using but I wanted to be sure we were both on the same page.

As I have been walking myself through this using sessions to trck this seems like a strange way to do it. You would be better off just using on page methods and staying away from using the session to store the offsets or results.

Is there any particular reason you want to do it using sesions?

Naghmeh

5:32 am on Apr 14, 2003 (gmt 0)

10+ Year Member



thank you for your reply and good description,
well there isn't any particular reason using sessions,(the most important reason is to learn how to use sessions)
i will try to use the way you mentiond,and learn about sessions after my problem is solved.

thanks again jatar
naghmeh

Naghmeh

3:02 pm on Apr 14, 2003 (gmt 0)

10+ Year Member



hi
i was just working on your solution,i follow up with this problem:
in my main script i have some select queries and for all other pages (for example page 2)i have a new script so, there should be a way to use the result of those queries?
and also, when i want to pass variable from page to page i use
<a href="NextPage.php?j=X">
is there a way that i can send more than one variable to next page?

thank you
Naghmeh

jatar_k

6:59 pm on Apr 14, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



is there a way that i can send more than one variable to next page?

yep, just keep tacking them on the end by using & between them.

like so ...
<a href="NextPage.php?j=X&var2=value&var3=value2">

Try to keep them to minimum if you can (2 or less). You may find that the links will not be spidered as they get longer.

Naghmeh

4:41 am on Apr 15, 2003 (gmt 0)

10+ Year Member



ok,
you advise that i dont use variables passed by link and also not session, so how can i do what i want?is there any other way that i dont know?

thank you
Naghmeh

jatar_k

7:32 pm on Apr 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, sorry Naghmeh, it does sound a little frustrating. For query strings try to stick with 2 or less.

If you have a set number of results you could even hard code the queries into each individual page, this doesn't work very well if the number of items will constantly change.

You could also use mod_rewrite [webmasterworld.com] but that can be very confusing if you are just starting out.

You can even use sessions for it but when I was working through some ideas it seemed like a more confusing way of doing it.