Vivid Lust Posted February 19, 2008 Share Posted February 19, 2008 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!!!!! Quote Link to comment Share on other sites More sharing options...
duclet Posted February 19, 2008 Share Posted February 19, 2008 You need to add session_start(); at the top of the code. Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted February 19, 2008 Author Share Posted February 19, 2008 I do but it says: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jacsta/public_html/site/profile.php:20) in /home/jacsta/public_html/site/menu.php on line Quote Link to comment Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 When he said top of code, he means the first line of code after <?php Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted February 19, 2008 Author Share Posted February 19, 2008 yes i know. menu.php: <?php session_start(); if(isset($_SESSION['myusername'])) echo "<a href=logout.php>Log Out</a>"; else echo "<a href=login.php>Click here to login!</a>"; ?> Which is called in profile.php Quote Link to comment Share on other sites More sharing options...
Dragen Posted February 19, 2008 Share Posted February 19, 2008 if it's included in another file, then it needs to be at the top of the other file. session_start must be before any output. Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted February 19, 2008 Share Posted February 19, 2008 If you've put 'session_start()' at the top of both login.php and the pages which you need to use the session details.. then it should be working. Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted February 19, 2008 Author Share Posted February 19, 2008 Dont worry Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted February 19, 2008 Author Share Posted February 19, 2008 Ok, theres no error, although the text is always click here to login, although i logged in ??? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 19, 2008 Share Posted February 19, 2008 Are you sure the login script is working properly? I notice in your SELECT statement you use "password='$encrypt'". Where is $encrypt getting set? also, after your header('location...'); put an exit; Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted February 19, 2008 Share Posted February 19, 2008 That would mean that $_session['myusername'] has not been assigned. Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted February 19, 2008 Author Share Posted February 19, 2008 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. Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted February 19, 2008 Share Posted February 19, 2008 $_SESSION['myusername'] = $myusername; Your declaring a session variable, without an open session in progress. Put in : session_start(); between <?php and $host Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 19, 2008 Share Posted February 19, 2008 also, you need to have $encrypt = md5($mypassword); after this line $mypassword = $_POST['mypassword']; Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted February 19, 2008 Author Share Posted February 19, 2008 Thanks, its working How could i compare the value of the session to the one in the database to get member info. Thanks. Quote Link to comment Share on other sites More sharing options...
duclet Posted February 20, 2008 Share Posted February 20, 2008 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 ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.