rklapwijk,
I tried your example and it did work, sessions are working on my server.
jassh,
I'm running on a Linux platform, sorry, your pyschic abilities need sharpening 😉
Daveyz1983,
That worked, it now shows the URL in the source code, thank you.
Again, this is how I have it set up, two pages to show you, the first will be the index.php page, then will be the functions.php page.
index.php:
<?
session_start(); //Start Session
require('functions.php');
do_header('Home Page'); // Place title name
do_menu(); // Display Menu
/* Start Main Page Info */
open_table('0','2','2','384','#FFFFFF');
echo"<TR><TD BGCOLOR=black><P CLASS=heading>Featured Product</TD></TR>\n"
."<TR><TD><A HREF=\"products.php?&action=show&prod_id=13\">"
."<IMG SRC=\"images/featured-7145.jpg\" WIDTH=380 HEIGHT=218 BORDER=0 ALT=\"Click on Image to learn more!\">"
."</A></TD></TR>\n";
close_table();
do_footer();
?>
functions.php - This contains the login stuff and all.
<?
session_start(); //Start Session
/* -------------------------------------- Database Config -------------------------------------------------------------- */
function db_connect()
{
$result = @mysql_pconnect("localhost", "******", "******");
if (!$result)
return false;
if (!@mysql_select_db("cpobase"))
return false;
return $result;
}
function db_result_to_array($result)
{
$res_array = array();
for ($count=0; $row = @mysql_fetch_array($result); $count++)
$res_array[$count] = $row;
return $res_array;
}
/* -------------------------------------- Validate Users -------------------------------------------------------------- */
if ($user && $passwd)
{
// if the user has just tried to log in
db_connect();
$query = "select * from cpo_employees where user='$user' and passwd='$passwd'";
$result = mysql_query($query);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$valid_user = $user;
session_register("valid_user");
}
}
function login()
{
open_table('0','2','2','180','#FFFFFF');
echo"<TR><TD BGCOLOR=black><P CLASS=heading>Login:</TD></TR>\n";
echo"<FORM ACTION=\"";
echo $_SERVER['PHP_SELF'];
echo"\" METHOD=post>\n"
."<TR><TD><P>User Name: <INPUT TYPE=\"text\" Name=\"user\" SIZE=10 MAXLENGTH=30></TD></TR>\n"
."<TR><TD><P>Password: <INPUT TYPE=\"password\" Name=\"passwd\" SIZE=10 MAXLENGTH=30></TD></TR>\n"
."<TR><TD><P><INPUT TYPE=\"submit\" VALUE=\"Login\"></TD></TR>\n"
."</FORM>\n";
close_table();
}
/* -------------------------------------- Table Functions ------------------------------------------------------------- */
function open_table($border,$cellspacing,$cellpadding,$width,$bgcolor)
{
echo "<TABLE BORDER=\"$border\" CELLSPACING=\"$cellspacing\" CELLPADDING=\"$cellpadding\" WIDTH=\"$width\" BGCOLOR=\"$bgcolor\">\n";
}
function close_table()
{
echo "</TABLE>\n";
}
/* --------------------------------------------- Head Functions ------------------------------------------------------------- */
function do_header($title)
{
echo"<HTML>\n"
."<HEAD><TITLE>$title</TITLE>\n";
include('includes/meta.php');
include('includes/styles.php');
include('includes/scripts.php');
echo"</HEAD>\n"
."<BODY>\n";
open_table_border('800');
echo"<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=\"800\" BGCOLOR=\"#FFFFFF\">\n"
."<TR><TD COLSPAN=2><TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0 WIDTH=\"800\" BGCOLOR=\"#000033\">\n"
."<TR><TD COLSPAN=3><IMG SRC=\"images/logo.jpg\" Height=80 Width=800 border=0></TD></TR>\n"
."<TR><TD WIDTH=150><P CLASS=\"heading\">".date('F jS Y')."</TD><TD WIDTH=500 ALIGN=\"center\"><P CLASS=\"heading\">$title</TD>"
."<TD ALIGN=right WIDTH=150><P CLASS=\"heading\">";
//Would like to have it welcome the user by name otherwise it will just say welcome. This part is not working, not showing name.
if (session_is_registered("valid_user"))
{
echo "<P class=\"heading\">Welcome $valid_user\n ";
}
else
{
echo "<P class=\"heading\">Welcome\n ";
}
echo"</TD></TR></TABLE></TD></TR>\n"
."<TR VALIGN=\"top\"><TD WIDTH=180>\n";
}
/* --------------------------------------------- Menu Functions ------------------------------------------------------------- */
function do_menu() //Creates Menu
{
open_table('0','1','1','100%','#FFFFFF');
echo"<TR><TD COLSPAN=2 BGCOLOR=black><P CLASS=heading>Menu</TD></TR>\n";
$conn = db_connect();
$query = "select * from cpo_pages WHERE active='1'";
$result = @mysql_query($query);
$num_results = mysql_num_rows($result);
$i = 0;
while($row = mysql_fetch_array($result))
{
echo"<TR VALIGN=top><TD><IMG SRC=\"images/diamond_icon.gif\" WIDTH=10 HEIGHT=10 BORDER=0></TD><TD><A CLASS=\"menu\" HREF=\"".$row[url]."\">".$row[title]."</A></TD></TR>\n";
}
close_table();
echo"<br>";
//Now lets check if the user is vaild, if so, remove login box and show menu specific for that users level, also display their name.
if (session_is_registered("valid_user"))
{
open_table('0','2','2','180','#FFFFFF');
echo"<TR><TD BGCOLOR=black><P CLASS=heading>Welcome ".$_SESSION['valid_user']."</TD></TR>\n";
//Show menus based on user levels
db_connect();
$query = "select * from cpo_employees WHERE user ='$valid_user'";
$result = @mysql_query($query);
$num_results = mysql_num_rows($result);
$i = 0;
while($row = mysql_fetch_array($result))
{
if ($row[level] == admin)
{
echo"<TR><TD><P class=\"menu\">\n";
echo"• <a class=\"menu\" href=\"admin.php\">Administrative</a><br>\n";
echo"• <a class=\"menu\" href=\"profiles.php\">Update Profile</a><br>\n";
echo"</TD></TR>\n";
}
else if($row[level] == sales)
{
echo"<TR><TD><P class=\"menu\">\n";
echo"• <a class=\"menu\" href=\"profiles.php\">Update Profile</a><br>\n";
echo"</TD></TR>\n";
}
else
{
echo"<TR><TD><P class=\"menu\">\n";
echo"• <a class=\"menu\" href=\"profiles.php\">Update Profile</a><br>\n";
echo"</TD></TR>\n";
}
}
close_table();
}
//If not login yet, show login box
else
{
login();
}
}
}
/* --------------------------------------------- Footer Functions ------------------------------------------------------------- */
function do_footer()
{
echo"</TD></TR>\n"
."<TR><TD COLSPAN=2 BGCOLOR=\"#000033\">\n"
."<P ALIGN=center class=\"heading\">© 1999-".date('Y')." CPO LTD, INC. All rights reserved.\n"
."</TD></TR>\n"
."</TABLE>\n";
close_table_border();
echo"</BODY>\n"
."</HTML>\n";
}
?>
Thanks for all your help guys, this is kinda driving me nutz. I recently changed servers to another hosting company and I'm not sure how much different they are set up from my old one.