session vars

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
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

session vars

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Post by mojeIme »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Post by mojeIme »

I use class.Session .Works ok first time
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Sorry, clueless.
Maybe the session mechanism must be initialized.
Maybe the data is overwritten or set to null.
Can't tell.
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Post by mojeIme »

OK thanks anyway
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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

Code: Select all

$Session->p($Session);
return?
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Post 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;
		}
	}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Post by mojeIme »

Ok thanks, you was very helpfull. And yes, that unset() is not needed ,thanks a lot!
Post Reply