Jump to content

Archived

This topic is now archived and is closed to further replies.

klaroen

Sessies not allowed or something....

Recommended Posts

Oke, I got this little login script but their seems to be something wrong about superglobals.. [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

[b]Objective[/b]
I want that the user who logges in is stored in a session and I can get his information by connecting with my database with the session

[b]The scripts I now have[/b]

### login.php ###
----------------------
<?php
session_start();

if ($Submit) {

$DBHost = "localhost";
$DBLogin = "klaroen_data";
$DBPassword = "******";
$DBDatabase = "klaroen_data";

mysql_connect("$DBHost", "$DBLogin", "$DBPassword");
@mysql_select_db("$DBDatabase");

$LoginNaam = addslashes($LoginNaam);
$LoginPassword = addslashes($LoginPassword);
$LoginMail = addslashes($LoginMail);

$Query = mysql_query("SELECT * FROM koc_users WHERE username = '$LoginNaam' AND password = '$LoginPassword' AND email = '$LoginMail'");
$Results = mysql_num_rows($Query);

if ($Results == '1') {

$_SESSION['login'] = "1";
header ("Location: base.php");

}
else {
header ("Location: wronglogin.php");
}

}
?>


----------------------

### base.php (page after login.php) ###
-------------------------------------------------
<?php
session_start();

if ($_SESSION['Login'] == "1") {
?>
<?php
$query = "SELECT * FROM koc_users WHERE username = '".$_SESSION['Login']."'";
$st=mysql_query($query);
$recs=mysql_num_rows($st);
$row=mysql_fetch_assoc($st);


print <<<ENDHTML
<table width="100%">
<tr>
<td width="50%" valign="top" style="padding-right: 25px;">
<table class="table_lines" width="100%" cellspacing="0" cellpadding="6" border="0">
<tr>
<th colspan="2" align="center">User Info</th>
</tr>
<tr>
<td><b>Name</b>
</td>
<td>$row->username</td>
</tr>
</table>
</td>
</tr>
</table>
ENDHTML;


?>
<?php
}
else {
include("mustlogin.php");
}
?>

-------------------------------------------------------




What must I do to let it work to display his informations??($row->username == doesn't work)!!!

HELP!

Share this post


Link to post
Share on other sites
('$submit');

isset(['submit']);

$_POST(['submit']);


[code]

database connection

select database WHERE id='$id'";

$result=mysql_query($query);

while($row=mysql_fetch_assoc($result) {

echo $row['name'];

}
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=385027:date=Jun 17 2006, 05:54 PM:name=klaroen)--][div class=\'quotetop\']QUOTE(klaroen @ Jun 17 2006, 05:54 PM) [snapback]385027[/snapback][/div][div class=\'quotemain\'][!--quotec--]
But I haven't got the $id from anywhere...
[/quote]

[code]
<td>$row->username</td>
to
<td><? echo$row['username'];?></td>
[/code]

my code is an example ok.

Share this post


Link to post
Share on other sites
But my sessions aren't working proper either!

If I loggin and get redirected to base.php
I'm not allowed (so not logged in..)

Share this post


Link to post
Share on other sites
[!--quoteo(post=385033:date=Jun 17 2006, 06:13 PM:name=klaroen)--][div class=\'quotetop\']QUOTE(klaroen @ Jun 17 2006, 06:13 PM) [snapback]385033[/snapback][/div][div class=\'quotemain\'][!--quotec--]
But my sessions aren't working proper either!

If I loggin and get redirected to base.php
I'm not allowed (so not logged in..)
[/quote]

Chage the submit code ok like this or an example above.
[code]
if ('$Submit') {
[/code]

Share this post


Link to post
Share on other sites
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/klaroen/domains/kingsofwar.be/public_html/kocclone/base.php on line 108


...
DAMN! :p

Share this post


Link to post
Share on other sites
login.php
[code]

<?php session_start();


// connect to database.

$DBHost = "localhost";
$DBLogin = "klaroen_data";
$DBPassword = "******";
$DBDatabase = "klaroen_data";

mysql_connect("$DBHost", "$DBLogin", "$DBPassword");
@mysql_select_db("$DBDatabase");


// if theres a post submit.

if ($_POST(['submit'] ) ) {


$Query = mysql_query("SELECT * FROM koc_users WHERE username = '$LoginNaam' AND password = '$LoginPassword' AND email = '$LoginMail'");

$Results = mysql_num_rows($Query);

// if user exists goto base.php

if ($Results == '1') {

session_register('email');
session_register('name');
session_rgister('password')

header ("Location: base.php");



}else{

header ("Location: wronglogin.php");

}


}
?>
[/code]






base.php
[code]

//if session exists.

<?php  session_start();

if ( (! $_SESSION['username'] )&& (! $_SESSION['password'])) {
?>


//select with while loop.

<?php
$query = "SELECT * FROM koc_users WHERE username = '".$_SESSION['username']."' and password='".$_SESSION['password']."' ";

$st=mysql_query($query);

while($row=mysql_fetch_assoc($st)){

?>


<table width="100%">
<tr>
<td width="50%" valign="top" style="padding-right: 25px;">
<table class="table_lines" width="100%" cellspacing="0" cellpadding="6" border="0">
<tr>
<th colspan="2" align="center">User Info</th>
</tr>
<tr>
<td><b>Name</b>
</td>
<td><? echo $row['username']; ?></td>
</tr>
</table>
</td>
</tr>
</table>

<?}?>


<?php

//if not logged in goto correct page.

}else{

header("location:  mustlogin.php ");

}

?>
[/code]

Share this post


Link to post
Share on other sites
Look, I use these print<<<ENDHTML and ENDHTML; things
so how must I print my name now?

like so?: <td> $row['username'] </td> ???

Share this post


Link to post
Share on other sites
isn't it "while($row=mysql_fetch_assoc($st)){" in stat of "while($row=mysql_fetch_assoc($st){ ???

AND

if ((! $_SESSION['username'] )&& ($_SESSION['password'])) { in stat of if ((! $_SESSION['username'] )&& $_SESSION['password'])) {
???

Share this post


Link to post
Share on other sites
[!--quoteo(post=385074:date=Jun 17 2006, 07:53 PM:name=klaroen)--][div class=\'quotetop\']QUOTE(klaroen @ Jun 17 2006, 07:53 PM) [snapback]385074[/snapback][/div][div class=\'quotemain\'][!--quotec--]
isn't it "while($row=mysql_fetch_assoc($st)){" in stat of "while($row=mysql_fetch_assoc($st){ ???

AND

if ((! $_SESSION['username'] )&& ($_SESSION['password'])) { in stat of if ((! $_SESSION['username'] )&& $_SESSION['password'])) {
???
[/quote]

correct my fault sorry.

Share this post


Link to post
Share on other sites
lol , (thanks for the help) , but here is the next error:
Parse error: syntax error, unexpected '[', expecting ')' in /home/klaroen/domains/kingsofwar.be/public_html/kocclone/login.php on line 18

and line 18 says: if ($_POST(['submit'] ) {

so....

Share this post


Link to post
Share on other sites
login.php
[code]

<?php session_start();


// connect to database.

$DBHost = "localhost";
$DBLogin = "klaroen_data";
$DBPassword = "******";
$DBDatabase = "klaroen_data";

mysql_connect("$DBHost", "$DBLogin", "$DBPassword");
@mysql_select_db("$DBDatabase");


// if theres a post submit.

if ($_POST(['submit'] ) ) {


$Query = mysql_query("SELECT * FROM koc_users WHERE username = '$LoginNaam' AND password = '$LoginPassword' AND email = '$LoginMail'");

$Results = mysql_num_rows($Query);

// if user exists goto base.php

if ($Results == '1') {

session_register('email');
session_register('name');
session_rgister('password')

header ("Location: base.php");



}else{

header ("Location: wronglogin.php");

}


}
?>
[/code]






base.php
[code]

//if session exists.

<?php  session_start();

if ( (! $_SESSION['username'] )&& (! $_SESSION['password'])) {
?>


//select with while loop.

<?php
$query = "SELECT * FROM koc_users WHERE username = '".$_SESSION['username']."' and password='".$_SESSION['password']."' ";

$st=mysql_query($query);

while($row=mysql_fetch_assoc($st)){

?>


<table width="100%">
<tr>
<td width="50%" valign="top" style="padding-right: 25px;">
<table class="table_lines" width="100%" cellspacing="0" cellpadding="6" border="0">
<tr>
<th colspan="2" align="center">User Info</th>
</tr>
<tr>
<td><b>Name</b>
</td>
<td><? echo $row['username']; ?></td>
</tr>
</table>
</td>
</tr>
</table>

<?}?>


<?php

//if not logged in goto correct page.

}else{

header("location:  mustlogin.php ");

}

?>
[/code]

edited ok

Share this post


Link to post
Share on other sites
not totally :p

in login your 3th session register is spelled wrong :p :D

phhh, f** it still not working!! Why not!!
Well, let's try again:
____________________________________________

menu.php (the login form)
---------------------------------
[code]
<form action="login.php" method="post">
<table align="center" class="small" style="padding: 0px 0px 5px 0px;" width="130">
    <tr>
        <td align="center"><font color="black">Username:</font></td>
    </tr>
    <tr>
        <td align="center"><input class="login_input" type="text" name="LoginNaam" value=""></td>
    </tr>
    <tr>
        <td align="center"><font color="black">Email:</font></td>
    </tr>

    <tr>
        <td align="center"><input class="login_input" type="text" name="LoginMail" value=""></td>
    </tr>
    <tr>
        <td align="center"><font color="black">Password:</font></td>
    </tr>
    <tr>
        <td align="center"><input class="login_input" type="password" name="LoginPassword"></td>

    </tr>
    <tr>
        <td align="center" style="padding-top: 5px;"><input type="hidden" name="Submit" value="1"><input class="login_input" type="submit" value="Login" style="width: 50px;"></td>
    </tr>
</table>
</form>
[/code]

-------------------------------------
-------------------------------------


login.php
--------------
[code]
<?php
session_start();


// connect to database.

$DBHost = "localhost";
$DBLogin = "klaroen_data";
$DBPassword = "******";
$DBDatabase = "klaroen_data";

mysql_connect("$DBHost", "$DBLogin", "$DBPassword");
@mysql_select_db("$DBDatabase");


// if theres a post submit.

if ($_POST(['Submit'] ) {


$Query = mysql_query("SELECT * FROM koc_users WHERE username = '$LoginNaam' AND password = '$LoginPassword' AND email = '$LoginMail'");

$Results = mysql_num_rows($Query);

// if user exists goto base.php

if ($Results == '1') {

session_register('email');
session_register('name');
session_register('password');

header ("Location: base.php");



}else{

header ("Location: wronglogin.php");

}


}
?>
[/code]

---------------------------
---------------------------


base.php
-------------
[code]
<?php  
session_start();

if ((! $_SESSION['username'] )&& (! $_SESSION['password'])) {
?>

<!-- *************** -->
<!-- Check the login -->
<!-- And else...     -->
<!-- *************** -->
<?php
include("connect.php");
?>
<?php
$query = "SELECT * FROM koc_users WHERE username = '".$_SESSION['username']."' and password='".$_SESSION['password']."' ";
$st=mysql_query($query);
while($row=mysql_fetch_assoc($st)){
?>
                <table width="100%">
                <tr>
                <td width="50%" valign="top" style="padding-right: 25px;">
                <table class="table_lines" width="100%" cellspacing="0" cellpadding="6" border="0">
                <tr>
                <th colspan="2" align="center">User Info</th>
                </tr>
                <tr>
                <td><b>Name</b>
                </td>
                <td><? echo $row['username']; ?></td>
                </tr>
</table>
</td>
</tr>
</table>
<? } ?>


<?php

//if not logged in goto correct page.

}else{

header("location:  mustlogin.php ");

}

?>
[/code]
-------------------------------------


If we can't solve this in the next 30 min, I think I'll quite for this evening (22:26 here)
Fingers Crosses! :p
klaroen

Share this post


Link to post
Share on other sites

×

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.