mysterbx Posted June 16, 2008 Share Posted June 16, 2008 hello, could you help me out here? I am trieng to make a rating system on my site... Herre the code: <?php $id="1"; $_SESSION[$id]="aaa"; session_start(); if(isset($_SESSION[$id])) { echo "works"; } else { echo "doesnt"; } ?> i can never set the value for $id, if for example: $id="0000"; $_SESSION[$id]="aaa"; result should be $_SESSION[$id]="aaa"; but it doesnt work, i get no result, session doesnt create... Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/ Share on other sites More sharing options...
.josh Posted June 16, 2008 Share Posted June 16, 2008 need to put session_start before trying to use session variables. Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-566537 Share on other sites More sharing options...
mysterbx Posted June 16, 2008 Author Share Posted June 16, 2008 yes i know... i tried all the ways, nothing seems to work.. i tried this (since you said that i should put it in the front): <?php session_start(); $id="1"; $_SESSION[$id]="aaa"; if(isset($_SESSION[$id])) { echo "works"; } else { echo "doesnt"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-566545 Share on other sites More sharing options...
revraz Posted June 16, 2008 Share Posted June 16, 2008 Do you have errors being displayed? Are you getting any Header errors? Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-566549 Share on other sites More sharing options...
.josh Posted June 16, 2008 Share Posted June 16, 2008 code itself works fine. Problem is elsewhere. Sessions not being allowed, maybe cookies set not being allowed in your browser. edit: assuming that that's the entire contents of your file ^ Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-566552 Share on other sites More sharing options...
DarkWater Posted June 16, 2008 Share Posted June 16, 2008 You're trying to set it to $1, which contains "1". Try putting $1 in single quotes if you really want it to be: $_SESSION['$1'] Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-566557 Share on other sites More sharing options...
revraz Posted June 16, 2008 Share Posted June 16, 2008 I'm thinking you are using a editor that is putting a BOM character in front, and you are not showing errors so you don't see the "output already started" error. Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-566572 Share on other sites More sharing options...
mysterbx Posted June 16, 2008 Author Share Posted June 16, 2008 Ok... i made this code: (it works) <?php if(isset($rate) && !preg_match("#".$id."#ise",$_SESSION['rate'])) { $searchdl=mysql_num_rows(mysql_query("select * from downloads where id='$id'")); if($searchdl==1 && $rateid>0 && $rateid<6) { $_SESSION['rate']=$_SESSION['rate']." $id"; // DO SOMETHING // DO SOMETHING // DO SOMETHING } $sname=preg_replace("#(www.|http\:\/\/)#ise","",$siteurl); if(preg_match("#".$sname."#ise",$_SERVER["HTTP_REFERER"])) { header("location: ".$_SERVER["HTTP_REFERER"].""); } else { header("location: $siteurl/"); } die(); ?> } but when i remove cache and cookies the session disappers... how can i make it unexpirable? or make it expire after some time... something like "session_cache_limiter ('private_no_expire, must-revalidate');" (it doesnt work) Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-566827 Share on other sites More sharing options...
mysterbx Posted June 17, 2008 Author Share Posted June 17, 2008 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-567175 Share on other sites More sharing options...
r-it Posted June 17, 2008 Share Posted June 17, 2008 ini_set('session.gc_maxlifetime', 600*60); Quote Link to comment https://forums.phpfreaks.com/topic/110427-session_start/#findComment-567210 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.