Forum Moderators: coopster
Here is a portion of the code from the audio3.php page:
<?php
session_start();
//prevents caching
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();
$tbl_name="authorize"; // Table name
//require the config file
require ("/home/zackpowe/public_html/downloads/config.php");
require ("/home/zackpowe/public_html/downloads/functions.php");
// Connect to server and select databse.
mysql_connect("$server", "$dbusername", "$dbpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Some functions
/**
* Get the contents of a directory.
* returns the contents in an array or false
* on completion.
*/
function getDirFiles($dirPath)
{
// if the passed var isn't a dir
if(!is_dir($dirPath))
{
// if debugging
echo 'Error: var is not a dir.';
return false;
}
// if we can't open the dir
if (!$handle = opendir($dirPath))
{
// if debugging
echo 'Error: can not open dir.';
return false;
}
while (false!== ($file = readdir($handle)))
{
if ($file!= "." && $file!= "..")
{
$filesArr[] = trim($file);
}
}
closedir($handle);
sort($filesArr);
reset($filesArr);
return($filesArr);
}
while($row = mysql_fetch_array($result));
$downloadPath = "/home/zackpowe/public_html/downloads/";
$audioPath = $downloadPath ."audio/";
$path = $audioPath . $row['username']. "/";
$file_list = getDirFiles($path);
{
$file_list = getDirFiles("/home/zackpowe/public_html/downloads/audio/" . $row['username'] . "/");
$count = count($file_list);
?>
[/code]
if ($logged_in_correctly)){
//other session variables
$_SESSION['username'] = $row['username'];
}
then:
$downloadPath = "/home/zackpowe/public_html/downloads/";
$audioPath = $downloadPath ."audio/";
$path = $audioPath . $_SESSION['username']. "/";
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
what you COULD do is, upon succesful login, store the user's id from the table on the login.php page to a session variable ($_SESSION['user_id'] or something like that), then query for that specific id when you need the associated username
$sql="SELECT * FROM $tbl_name"." WHERE user_id =".mysql_real_escape_string($_SESSION['user_id']."";
$result=mysql_query($sql);
this is the most easy way for you I think
you would set the $_SESSION variable to store username once they are authenticated via your login script.
You need to make sure you use session_start [php.net] on every page to be able to access the $_SESSION data
Im trying to figure out where to put the $_SESSION line...on the redirect.php page or on the audio3.php page?
Here is the latest code:
<?php
session_start();
//prevents caching
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();
$tbl_name="authorize"; // Table name
//require the config file
require ("/home/zackpowe/public_html/downloads/config.php");
require ("/home/zackpowe/public_html/downloads/functions.php");
// Connect to server and select databse.
mysql_connect("$server", "$dbusername", "$dbpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name"." WHERE username=".mysql_real_escape_string($_SESSION['username'].""; //line 20
$result=mysql_query($sql);
// Some functions
/**
* Get the contents of a directory.
* returns the contents in an array or false
* on completion.
*/
function getDirFiles($dirPath)
{
// if the passed var isn't a dir
if(!is_dir($dirPath))
{
// if debugging
echo 'Error: var is not a dir.';
return false;
}
// if we can't open the dir
if (!$handle = opendir($dirPath))
{
// if debugging
echo 'Error: can not open dir.';
return false;
}
while (false!== ($file = readdir($handle)))
{
if ($file!= "." && $file!= "..")
{
$filesArr[] = trim($file);
}
}
closedir($handle);
sort($filesArr);
reset($filesArr);
return($filesArr);
}
if ($logged_in_correctly)){
//other session variables
$_SESSION['username'] = $row['username'];
}
while($row = mysql_fetch_array($result));
$downloadPath = "/home/zackpowe/public_html/downloads/";
$audioPath = $downloadPath ."audio/";
$path = $audioPath . $row['username']. "/";
$file_list = getDirFiles($path);
{
$file_list = getDirFiles("/home/zackpowe/public_html/downloads/audio/" . $row['username'] . "/");
$count = count($file_list);
?>
<html>
<head>
<html>
<head>
<title>Zack Powers ¦ Client downloads.</title>
<link href="/style.css" rel="Stylesheet" rev="Stylesheet">
</head>
<body background="/images/background.gif" bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" topmargin=0 leftmargin=0 rightmargin=0>
<img src="/images/header.gif"><br />
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="110">
</td>
<td width="*" class="regular">
<table border=0 width=60% bgcolor=0 cellpadding=5 cellspacing=0>
<tr>
<td bgcolor=#eeeeee style="font-family: Tahoma; font-size: 11px;"><b>
File Name (<? echo $_SESSION['username'];?>)
</b></td>
and the code continues...
Here is the latest code:
<?php
session_start();
//prevents caching
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();
$tbl_name="authorize"; // Table name
//require the config file
require ("/home/zackpowe/public_html/downloads/config.php");
require ("/home/zackpowe/public_html/downloads/functions.php");
// Connect to server and select databse.
mysql_connect("$server", "$dbusername", "$dbpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Some functions
/**
* Get the contents of a directory.
* returns the contents in an array or false
* on completion.
*/
function getDirFiles($dirPath)
{
// if the passed var isn't a dir
if(!is_dir($dirPath))
{
// if debugging
echo 'Error: var is not a dir.';
return false;
}
// if we can't open the dir
if (!$handle = opendir($dirPath))
{
// if debugging
echo 'Error: can not open dir.';
return false;
}
while (false!== ($file = readdir($handle)))
{
if ($file!= "." && $file!= "..")
{
$filesArr[] = trim($file);
}
}
closedir($handle);
sort($filesArr);
reset($filesArr);
return($filesArr);
}
if ($logged_in_correctly){
//other session variables
$_SESSION['username'] = $row['username'];
}
while($row = mysql_fetch_array($result));
$downloadPath = "/home/zackpowe/public_html/downloads/";
$audioPath = $downloadPath ."audio/";
$path = $audioPath . $row['username']. "/";
$file_list = getDirFiles($path);
{
$file_list = getDirFiles("/home/zackpowe/public_html/downloads/audio/" . $_SESSION['username'] . "/");
$count = count($file_list);
?>
<html>
<head>
<title>Zack Powers ¦ Client downloads.</title>
<link href="/style.css" rel="Stylesheet" rev="Stylesheet">
</head>
<body background="/images/background.gif" bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" topmargin=0 leftmargin=0 rightmargin=0>
<img src="/images/header.gif"><br />
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="110">
</td>
<td width="*" class="regular">
<table border=0 width=60% bgcolor=0 cellpadding=5 cellspacing=0>
<tr>
<td bgcolor=#eeeeee style="font-family: Tahoma; font-size: 11px;"><b>
File Name (<? echo $_SESSION['username'];?>)
</b></td>
and html continues...