We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
Sessions
Topic Started: Jun 27 2005, 02:17 PM (797 Views)
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
*yoinkage*
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
You have to send the session_start() before any output. Example:

Will NOT work
 

<HTML>
<HEAD>
<TITLE>Test</title>
</HEAD>
<BODY>
<?php session_start(); ?>
Please Log In
</BODY>
</HTML>


Will Work
 

<?php session_start(); ?>
<HTML>
<HEAD>
<TITLE>Test</title>
</HEAD>
<BODY>
Please Log In
</BODY>
</HTML>


This goes the same for any echo's, prints, etc.

Not sure if that's the specific problem, but that's a problem.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Well how would I echo things out in the content div if it has to be at the top?
Offline Profile Quote Post Goto Top
 
FearKiller
Member Avatar
www.drewscripts.com
[ *  *  *  *  * ]
Das Ein
June 27, 2005 02:04 PM
Well how would I echo things out in the content div if it has to be at the top?

How wouldn't you? session_start() MUST be before any output is sent to the user weither it's HTML, echo statements, or even blank lines. Also one of your <br /> seems to have stray quotes after it and you should really use © instead of the copyright symbol itself. That may fix the problems with the footer.

Code:
 
<?php
session_start();
?>
<html>
<head>
<title>My title</title>
</head>
<body>
<div>
<?php
$_SESSION['user'] = 'The Username';
echo $_SESSION['user'];
?>
</div>
</body>
</html>
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Ok so now I have:

Quote:
 
<?php
session_start();
?>
<?php
//dbconnect
?>

//html

<div id="content">
<?php
$username = $_post["username"];
$password = $_post["password"];
$ck_log = mysql_query("SELECT username FROM members WHERE username = '$username' AND password = '$password'");
if(mysql_num_rows($ck_log) == 1) {
$_SESSION['username'] = mysql_result($ck_log, 0);
} else {
$alert = 'Invalid username and/or password';
}
?>
</div>

//html


Now I don't get an error, but don't appear to be logged in. When I go to mycontrols I get my not logged in error.
Offline Profile Quote Post Goto Top
 
FearKiller
Member Avatar
www.drewscripts.com
[ *  *  *  *  * ]
Try placing session_start() at the top of mycontrols.php as well.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Already did:

Quote:
 
<?php
session_start();
?>

HTML HERE


<div id="content">

<?php

$dbh=mysql_connect ("localhost", "dasein_dasein", "*************") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("dasein_users");

if(isset($_SESSION['username'])) {
echo "Hi";
} else {
echo "You're not logged in. This feature is only avialable to those who are logged in!";
echo "<br />";
echo "Login ";
echo "<a href=\"http://www.*yoink*.com/login.php\">here.</a>";
}

?>


HTML HERE
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
I decided to go another way with this. Now I am not getting an error, but nothing is happening:

Quote:
 
<?php
echo "fixed :).";
?>


EDIT: Sorry about the double post thought Fearkiller was above me :$.
Offline Profile Quote Post Goto Top
 
FearKiller
Member Avatar
www.drewscripts.com
[ *  *  *  *  * ]
$_post != $_POST

Try using CAPS.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
New problem:

Quote:
 

<?php
// I am 99% sure this is fine
$query = "SELECT status FROM members WHERE status = '$var'";
$result = mysql_query($query);
while ($fetch = mysql_fetch_array($result)) {
echo $fetch['username'];
}
?>


Same as usual no error, but nothing happens >_<. There is a little more to this code, but I am pretty sure it is fine.
If this code is ok I will post the other part to see if it is that.
Offline Profile Quote Post Goto Top
 
mathiaus
Member Avatar
mathiaus maximus™
[ *  *  *  *  *  * ]
your trying to fetch the username but in the query you only selected status

Code:
 
<?php
// I am 99% sure this is fine
$query = "SELECT status, username FROM members WHERE status = '$var'";
$result = mysql_query($query);
while ($fetch = mysql_fetch_array($result)) {
echo $fetch['username'];
}
?>
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
>_< I knew it was something stupid again. Thanks :$.
Offline Profile Quote Post Goto Top
 
lilhawk2892
Member
[ *  * ]
wut is a session is it like a one hour chat sort of thing or is it like registereing for somthing like ytv.com
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
Sessions are a method of Authentication used to log people in, and stuff like that.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Like a server-side cookie.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Technology Chat · Next Topic »
Add Reply
  • Pages:
  • 1