Jump to content

Sessies not allowed or something....


klaroen

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!

Link to comment
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.
Link to comment
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]
Link to comment
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]
Link to comment
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'])) {
???
Link to comment
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.
Link to comment
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....
Link to comment
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
Link to comment
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
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.