Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,730 members, 7,817,009 topics. Date: Friday, 03 May 2024 at 10:48 PM

Session Variables - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Session Variables (2729 Views)

Passing Php Variables To Javascript (2) (3) (4)

(1) (Reply) (Go Down)

Session Variables by phantomcat(m): 8:55am On Jul 29, 2008
guys i need some help here.

I am working on a php mysql job, the issue I've created an app that i want to use session variables for. so that when a user logs in, he will be identified sitewide. i am working with dreamweaver. though i have put in the server behaviours on the pages it is not showing the loged in user details.

please i am open for suggestions
Re: Session Variables by yawatide(f): 12:15pm On Jul 29, 2008
phantom,

At times like this, it helps to show us your code. Perhaps you are using the code right but within the wrong context. There is no way of knowing unless you paste something for us here.
Re: Session Variables by TechPros(m): 3:21pm On Jul 29, 2008
post your code so we can help you out, yawe is right there is no way anyone can help without seeing your code.
Re: Session Variables by phantomcat(m): 3:29pm On Jul 29, 2008
this is the source code from one of the pages.

<?php require_once('Connections/gidox.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != ""wink){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true"wink){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);

$logoutGoTo = "logout.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo"wink;
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == ""wink && true) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "sorry.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?"wink) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
mysql_select_db($database_gidox, $gidox);
$query_news = "SELECT * FROM news ORDER BY `no` ASC";
$news = mysql_query($query_news, $gidox) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);
$totalRows_news = mysql_num_rows($news);

$colname_user = "-1";
if (isset($_SESSION['ID'])) {
$colname_user = (get_magic_quotes_gpc()) ? $_SESSION['ID'] : addslashes($_SESSION['ID']);
}
mysql_select_db($database_gidox, $gidox);
$query_user = sprintf("SELECT * FROM reg WHERE ID = %s", $colname_user);
$user = mysql_query($query_user, $gidox) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);

// Trim by length (by FELIXONE.it)
function TrimByLength($str, $len, $word) {
$end = "";
if (strlen($str) > $len) $end = ", ";
$str = substr($str, 0, $len);
if ($word) $str = substr($str,0,strrpos($str," "wink+1);
return $str.$end;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Go-GO Global member downline</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="images/BrightSide1.css" type="text/css" />
<style type="text/css">
<!--
.style3 {color: #CC0000; font-weight: bold; }
.style4 {
color: #000099;
font-style: italic;
}
.style5 {color: #330000}
.style1 { color: #6297BC;
font-weight: bold;
}
-->
</style>
</head>
<body>
<!-- wrap starts here -->
<div id="wrap">
<div id="header">
<h1 id="logo">Gidok<span class="green"> Global</span><span class="gray"> Enterpise</span></h1>
<h2 id="slogan">, giving you a lift.</h2>
<!-- Menu Tabs -->
<ul>
<li><a href="index.html"><span>Home</span></a></li>
<li><a href="admin_area.php"><span>About</span></a></li>
<li><a href="registration.php"><span>Register</span></a></li>
<li><a href="support.php"><span>Support</span></a></li>
<li><a href="contact.php"><span>Contact</span></a></li>
</ul>
</div>
<!-- content-wrap starts here -->
<div id="content-wrap"> <img src="images/headerphoto.jpg" width="820" height="120" alt="headerphoto" class="no-border" />
<div id="sidebar" >
<h1>&nbsp;</h1>
<ul class="sidemenu">
<li><a href="index.html">Home</a></li>
<li><a href="about.php">About us </a></li>
<li><a href="registration.php">Register</a></li>
<li><a href="<?php echo $logoutAction ?>"> Logout</a></li>
<li><a href="services.php">Services</a></li>
</ul>
<h1>Wise Words</h1>
<p>&quot;Men are disturbed, not by the things that happen,
but by their opinion of the things that happen.&quot;</p>
<p class="align-right">- Epictetus</p>
</div>
<div id="main">
<h1>Gato <span class="green">Investment <span class="gray">Project</span> </span></h1>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td colspan="2"><strong>Welcome <span class="style5">
<?php if ($totalRows_user > 0) { // Show if recordset not empty ?>
<?php /*START_PHP_SIRFCIT*/ if ($row_user['ID']=="-1"wink{ ?>
<?php echo $row_user['firstname']; ?>
<?php } /*END_PHP_SIRFCIT*/ ?>
<?php } // Show if recordset not empty ?>
<?php if ($totalRows_user > 0) { // Show if recordset not empty ?>
<?php echo $row_user['surname']; ?>
<?php } // Show if recordset not empty ?></span></strong></td>
</tr>
<tr>
<td colspan="2"><div align="center" class="style4">Below is the status of your downline </div></td>
</tr>
<tr>
<td width="33%"><span class="style3">First Stage </span></td>
<td width="67%">&nbsp;</td>
</tr>
<tr>
<td><span class="style3">Second Stage </span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><span class="style3">Third Stage </span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><span class="style3">Forth Stage </span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><span class="style3">Fifth Stage </span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><span class="style3">Sixth Stage </span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><span class="style3">Seventh Stage </span></td>
<td>&nbsp;</td>
</tr>
</table>
<p>

</p>
</div>
<div id="rightbar">
<h1>News</h1>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td><?php do { ?>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td valign="top"><p><span class="style1"><?php echo $row_news['subject']; ?></span>

<?php echo $row_news['date']; ?>



<?php echo TrimByLength($row_news['news_details'], 100, true); ?></p>
</td>
</tr>
</table>
<?php } while ($row_news = mysql_fetch_assoc($news)); ?></td>
</tr>
</table>
<h1>&nbsp;</h1>
</div>
<!-- content-wrap ends here -->
</div>
<!-- footer starts here -->
<div id="footer">
<div class="footer-left">
<p class="align-left"> &copy; 2008 <strong>Gidok Global Enterprise </strong> |
Design by <a href="http://www.robertrover.com/">Robert Rover Ent.</a></p>
</div>
</div>
<!-- footer ends here -->
<!-- wrap ends here -->
</div>
</body>
</html>
<?php
mysql_free_result($news);

mysql_free_result($user);
?>


expecting ur reply

Re: Session Variables by yawatide(f): 3:44pm On Jul 29, 2008
wow phantom! When we said paste your code, we didn't really mean paste all of it tongue

In any event, I assume when you say, it is not showing any details, you mean the first and last name. Am I right? If not, let us know. If I am, then other minor issues aside, I noticed the following in your code which might be the reason why:

1) You have this check done twice. why?
if (!isset($_SESSION)) {
session_start();
}

2) Why would you need the following to return -1?
if ($row_user['ID']=="-1"wink{
Chances are that if it is not -1, the details won't show.

Get back to us please. Thanks. By the way, thanks to your indentation. The code was very easy to read and follow.
Re: Session Variables by AbidemiA: 5:19pm On Jul 29, 2008
Why not set breakpoints and use variables to check if your program logic is correct?
Re: Session Variables by yawatide(f): 5:27pm On Jul 29, 2008
@Abidemi
And what of if he doesn't know anything about breakpoints (I don't know that he does or doesn't but I am just asking)? Perhaps a little tutorial wouldn't be too bad here tongue
Re: Session Variables by Nobody: 7:00pm On Jul 29, 2008
You are asking if $_SESSION['ID'] exist here

$colname_user = "-1";
if (isset($_SESSION['ID'])) {
  $colname_user = (get_magic_quotes_gpc()) ? $_SESSION['ID'] : addslashes($_SESSION['ID']);
}


did you create that session on a previous page, because dreamweaver uses $_SESSION['MM_Username'] to store the username of the logged in user

as far as i can see, the above code is correct

In whatever case. use this and it should work
<?php
mysql_select_db($database_gidox, $gidox);
$query_news = "SELECT * FROM news ORDER BY `no` ASC";
$news = mysql_query($query_news, $gidox) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);
$totalRows_news = mysql_num_rows($news);

$colname_user = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_user = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_gidox, $gidox);
$query_user = sprintf("SELECT * FROM reg WHERE username = '%s'", $colname_user);
$user = mysql_query($query_user, $gidox) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);

// Trim by length (by FELIXONE.it)
function TrimByLength($str, $len, $word) {
  $end = "";
  if (strlen($str) > $len) $end = ", ";
  $str = substr($str, 0, $len);
  if ($word) $str = substr($str,0,strrpos($str," "wink+1);
  return $str.$end;
}
?>

change the bolden text to the username column name of your reg table

(1) (Reply)

Is There Any Jumia Or Konga Affiliate Being Paid? / Bulk Sms Business Coaching 101 / How Do Get A Short Code Service

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 46
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.