leequalls Posted December 23, 2008 Share Posted December 23, 2008 I am using sessions and have called session_start(); and session_register("ref"); at the beginning of the code on the first page. I also set $_SESSION("ref") = $ref; when I use $_SESSION("ref") on the main page it works but when calling it on other pages it does not work. All pages start on the main page and I use include("page.php"). Link to comment https://forums.phpfreaks.com/topic/138115-solved-php-help-with-_session/ Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 Firstly, session_register has long been depricated and should no longer be needed. Are you calling session_start() on all pages requiring the use of the $_SESSION array? Link to comment https://forums.phpfreaks.com/topic/138115-solved-php-help-with-_session/#findComment-722002 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 Actually, post your code. $_SESSION("ref") should be $_SESSION["ref"]. $_SESSION is an array not a function. Link to comment https://forums.phpfreaks.com/topic/138115-solved-php-help-with-_session/#findComment-722003 Share on other sites More sharing options...
leequalls Posted December 23, 2008 Author Share Posted December 23, 2008 here is my code hope it helps. this is the index.php <?PHP session_start(); mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $mem = mysql_query("SELECT * FROM members"); $totmem = mysql_num_rows($mem); $totmem = $totmem; $random = rand(0,$totmem); if (!isset($_SESSION["ref"])) { $ref = $_GET['ref']; if ($ref == "" || $ref > $totmem) { $ref = $random; } $_SESSION["ref"] = $ref; } include("main.php"); $p = $_GET['p']; print " <div id=\"menu\"> <ul> <li><a href=\"/?p=h\">HOME</a></li> <li><a href=\"/?p=m\">MEMBERS</a></li> <li><a href=\"?p=j\">JOIN</a></li> <li><a href=\"?p=c\">CONTACT</a></li> </ul> </div><div id=\"content\"> "; if ($p == j) { include("signup.php"); } if ($p == u) { include("upgrade.php"); } if ($p == m) { include("members.php"); } if ($p == a) { if (!isset($_GET['i']) || !is_numeric($_GET['i']) && $_GET['i'] != "" ) { echo("Failed to resolve activation code!"); } else { $res = mysql_query("select email, ref from members where id=" . $_GET['i'] . " && status='Un-verified'"); if (mysql_num_rows($res) != 1) { echo("Failed to resolve activation code!"); } else { $email = mysql_result($res, 0, "email"); $myref = mysql_result($res, 0, "ref"); $my_stat = "Verified"; $res = mysql_query("update members set status='$my_stat' where id=" . $_GET['i']) or die ("Please contact $title Admin there was an error, listed below please inlcude with your contact request...<br><br>Error was:<br>" . mysql_error()); echo("<p align=center>Your account was activated!</p>"); echo("<form action=http://$siteurl" . "/?p=m method=post name=login><input type=hidden name=form value=sent><div align=center><b>You may now log in:</b><br>"); echo("E-mail:<br><input type=text name=email size=10 maxlength=100 value=$email><br>Password:<br><input type=password name=passwd size=10 maxlength=20><br><input type=submit value=\"Log in\"></div></form>\n"); }} } if ($p == h || $p == "") { } ?> I did not include session_start(); on each file.php listed in the menu do I need to? Link to comment https://forums.phpfreaks.com/topic/138115-solved-php-help-with-_session/#findComment-722012 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 I did not include session_start(); on each file.php listed in the menu do I need to? Yep, thats what I just said Link to comment https://forums.phpfreaks.com/topic/138115-solved-php-help-with-_session/#findComment-722017 Share on other sites More sharing options...
leequalls Posted December 23, 2008 Author Share Posted December 23, 2008 thanks that fixed the problem Link to comment https://forums.phpfreaks.com/topic/138115-solved-php-help-with-_session/#findComment-722027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.