Jump to content

Sessions not working ???


Vivid Lust

Recommended Posts

Please help.

 

Here are my codes:

 

Login:

<?php
//...
$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];
$sql = "SELECT *, member FROM $tbl_name WHERE email='$myusername' and password='$encrypt'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if($count==1){
$row = mysql_fetch_assoc($result);
$_SESSION['myusername'] = $myusername;
header("location:profile.php?member=".$row['member']);
}
else{
echo "Wrong Username or Password";
echo "<br>";
echo "<b>";
}
?>

 

Check session to display links:

<?php
if(isset($_SESSION['myusername']))
echo "<a href=logout.php>Log Out</a>";
else
echo "<a href=login.php>Click here to login!</a>";
?> 

Thats loads in advanced!!!!!  :D;);D:):P

Link to comment
Share on other sites

I think it will be easier to post my full scrips as follows:

 

<?php
$host = "localhost";
$username = "************";
$password = "************";
$db_name = "************";
$tbl_name = "members";
$encrypt = md5($mypassword);

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];
$sql = "SELECT *, member FROM $tbl_name WHERE email='$myusername' and password='$encrypt'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if($count==1){
$row = mysql_fetch_assoc($result);
$_SESSION['myusername'] = $myusername;
header("location:profile.php?member=".$row['member']);
}
else{
echo "Wrong Username or Password";
echo "<br>";
echo "<b>";
}
?>

 

 

<?php
session_start();
include ("counter.php");
$dbhost = 'localhost';
$dbuser = '************';
$dbpass = '************';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ;('Error
connecting to mysql');
$dbname = '************';
mysql_select_db($dbname);
$query = mysql_query( "SELECT member, fname, nick, dp, sname, relationship, mood, views, description, description2, country, joined, gender, dob FROM members WHERE member = '{$_GET['member']}'" )
or die(mysql_error());
$row = mysql_fetch_assoc($query);
$memberid = $_GET['member'];
function birthday ($birthday) { list($year,$month,$day) = explode("-",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($month_diff < 0) $year_diff--; elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--; return $year_diff; }
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD /XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $row['nick']; ?></title>
<link rel="stylesheet" type="text/css" href="css.css">
</head>
<body>
<div id="menu">
<?php
if(isset($_SESSION['myusername']))
echo "<a href=logout.php>Log Out</a>";
else
echo "<a href=login.php>Click here to login!</a>";
?>
</div>
<br><Br><br><Br>
<div id="profilewrap">
<div id="profileblock">
<div id="nick">
<?php
echo $row['nick'];
?>
</div>
<br>
<div id="leftblock">
<div id="#dp">
<?php
echo "<img src=";
echo $row['dp'];
echo " height=200 width=250>";
?>
</div>
<div id="info">
<b>Name:</b>
<?php
echo $row['fname'];
echo " ";
echo $row['sname'];
?>
<Br>
<b>Age:</b>
<?php
echo birthday($row['dob']);
?>
<br>
<b>Gender:</b>
<?php
echo $row['gender'];
?>
<br>
<b>Joined:</b>
<?php
echo $row['joined'];
?>
<br>
<b>Country:</b>
<?php
echo $row['country'];
?>
<br>
<b>Relationship Status:</b>
<?php
echo $row['relationship'];
?>
<br>
<b>Birthday:</b>
<?php

$date = $row['dob'];
$date2 = strtotime($date);
echo(date("jS F",$date2));
?>
</div>
</div>
<div id="midblock">
<div id="description">
<?php
echo $row['description'];
?>
</div>
</div>
<div id="rightblock">
<div id="stat2">
<b>Views:</b>
<?php
echo $row['views'];
?>


<br>
<b>Mood:</b>
<?php
echo $row['mood'];
?>
<br>
<b>Last Active:</b>
<br><br>
</div>
<div id="description2">
<?php
echo $row['description2'];
?>
</div>
</div>
<br class="clearer">

</div>
</body>
</html>

 

That should clear alot of things up.

Link to comment
Share on other sites

Well, if you stored the username or user id, then you can always make another call to MySQL to retrieve the member information.

<?php
$sql = sprintf('SELECT * FROM user_table WHERE username = "%s" LIMIT 1;',
               $username);
$query = mysql_query($sql) or die('SQL: '.$sql.'<br />Error: '.mysql_error());

// Now use the result
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.