Page 1 of 1
session vars
Posted: Mon Jul 31, 2006 7:44 am
by mojeIme
Hi,
I am having some problems with session vars .First page sends some vars with get method, and on the result page i put all those var into a session. That is all OK, i can see those vars by printing the session. Problem starts when i go to page 2,3... ,and that paging works with php self method. Then i print it again and the vars are gone. Any help, please?
Posted: Mon Jul 31, 2006 7:51 am
by volka
mojeIme wrote:and that paging works with php self method
so it's always the same script that is invoked?
May we see some code?
Posted: Mon Jul 31, 2006 7:54 am
by mojeIme
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Code: Select all
<?php
$rijec=(isset( $_POST['rijec'] )) ? $_POST['rijec'] : ((isset($_GET['rijec']))? $_GET['rijec'] : "");
$forum=(isset( $_POST['forum'] )) ? $_POST['forum'] : ((isset($_GET['forum']))? $_GET['forum'] : "");
$limit=(isset( $_POST['limit'] )) ? $_POST['limit'] : ((isset($_GET['limit']))? $_GET['limit'] : 10);
$page=(isset( $_POST['page'] )) ? $_POST['page'] : ((isset($_GET['page']))? $_GET['page'] : "1");
if(isset( $_POST['SubmitTrazi'] ) || isset( $_GET['SubmitTrazi'] )){
unset($_POST['SubmitTrazi']);unset($_GET['SubmitTrazi']);
$Session->set_value("uslovi_pretrage_f",array("rijec" => $rijec,"forum" => $forum,"limit" => $limit),0);
}
$Session->p($Session);
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Mon Jul 31, 2006 7:55 am
by mojeIme
I use class.Session .Works ok first time
Posted: Mon Jul 31, 2006 8:13 am
by mojeIme
The paging works on this princip :
Code: Select all
"<a href=\"".$_SERVER['PHP_SELF']."?$sub&page=".$i."\" title=\"Page ".$i."\">".$i."</a>"
where sub is just string to lead me to that serch page, that will be included in the main page.
Posted: Mon Jul 31, 2006 8:20 am
by volka
Sorry, clueless.
Maybe the session mechanism must be initialized.
Maybe the data is overwritten or set to null.
Can't tell.
Posted: Mon Jul 31, 2006 8:22 am
by mojeIme
OK thanks anyway
Posted: Mon Jul 31, 2006 8:23 am
by RobertGonzalez
Are you using native PHP sessions? Also, are you making sure to call your session_start() at the beginning of the page? Also, what does
return?
Posted: Mon Jul 31, 2006 8:27 am
by mojeIme
I returns ,first time:
Code: Select all
ClsSession Object
(
[sid] => aa4c3e8840f467ba900aaaf6b2e42838
[document_root] => C:/wamp/www
[user_ip] => 127.0.0.1
[host_ip] => 127.0.0.1
[http_user_agent] => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Deepnet Explorer 1.5.0; .NET CLR 2.0.50727)
[user_agent] => Mozilla
[agent_id] => 0
[http_accept] => */*
[user_accept] =>
[gd_version] => 1
[imageExt] => .png
[cache_expire] => 30
[gc_maxlifetime] => 1440
[cookie_lifetime] => 1800
[audio] => .mid
[image] => .gif
[uslovi_pretrage_f] => Array
(
[rijec] => this_is_search_word
[forum] => 0
[limit] => 10
)
)
On my main page ,it is initialized :
Code: Select all
require "./phpKlase/session.class.php";
session_start();
$Session = $HTTP_SESSION_VARS["Session"];
if(!is_object($Session) || $Session==NULL){
$Session = new ClsSession();
@session_register("Session");
$HTTP_SESSION_VARS["Session"] = $Session;
}
and the set value function looks like this:
Code: Select all
function set_value($name,$value,$overwrite="1"){
if($overwrite || !isset($this->$name)){
$this->$name = $value;
}
}
Posted: Mon Jul 31, 2006 8:33 am
by RobertGonzalez
There are a couple of things going on here.
1) You are including session functions and potentially session setting data before your call to session_start(), which should be at the top of the page before you do any sessionizing.
2) You are using session_register in conjunction with the $HTTP_SESSION_VAR long array session superglobal. This method has been 'retired' with all of the long array superglobals in favor of the current way ($_SESSION).
3) Why are you using unset() on your $_POST and $GET 'submitTrazi' var before setting the session vars?
Posted: Mon Jul 31, 2006 8:42 am
by mojeIme
Ok thanks, you was very helpfull. And yes, that unset() is not needed ,thanks a lot!