Jump to content

[SOLVED] PHP help with $_SESSION


leequalls

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.