Welcome Guest ( Log In | Register )



3 Pages V   1 2 3 >  
Reply to this topicStart new topic
> Writing And Testing My Own Login Script [solved]
Eggie
post Feb 21 2008, 06:24 PM
Post #1


Advanced Member
Group Icon

Group: Members
Posts: 130
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



i have this error
QUOTE
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/eggie/public_html/race.php:2) in /home/eggie/public_html/race.php on line 5

in every page i have with session start...what's the problem??


CODE
<title>Race</title>
<?php
include("style.css");
include("config.php");
session_start();
if(!session_is_registered(myusername)){
echo 'Your Session has Expired!';
exit;}

//If you click race...
if ($_GET['action']=='race')
{
$asa=$_POST['bike'];

if(!isset($asa))
{
echo 'You didn\'t select any bike!';
?>
<br>click <a href=race.php> HERE</a> to go back
<?php
exit;
}

else{

$rand=mt_rand(1,2);
  
if ($_POST['bike']==1) $trub='Derbi Senda 50';
if ($_POST['bike']==2) $trub='Honda NS 50 R';
if ($_POST['bike']==3) $trub='Suzuki ZR 50';
if ($_POST['bike']==4) $trub='Yamaha DT 50 MX';
if ($_POST['bike']==5) $trub='Aprilia RS 50';

echo'You raced against:';
echo $trub;
$name=$_SESSION['views'];


$res = mysql_query("select * from members where username = '$name'");
$wins1 = mysql_fetch_array($res);
$points=$wins1['points'];
$wo=$wins1['wins'];
$lo=$wins1['lose'];

//If random number is equal to 1 than set win +1
if($rand==1){
?>
</br>
<?php
$wo++;
$points=$points+100;
mysql_query("update members set wins=$wo where username = '$name'");
mysql_query("update members set points=$points where username = '$name'");
echo '<br>You won 100 points!';
?>
</br>
<table border="1">
<?php
echo'You have total of: ' .$points. ' points!';
?>
</table>
</br>
<?php
}

//else lose +1
else {

echo'<br><br>You lost!';
?>
<table border="1"><td>
<?php

echo'You have total of: ' .$points. ' points!';


?>
</td></table>

<?php
$lo++;

mysql_query("update members set lose=$lo where username = '$name'");

?>
</br>
<?php
}

//How many times you won overall
echo 'Wins:';
echo $wo;
?>
</br>
<?php
echo'Losses:';
echo $lo;


//race form
?>
<form name="form3" method="post" action="race.php">

    <input type=submit value="Go back">  

</form>
<?php



exit;


}
}

if ($_GET['action']!='race'){?>
<html>
<head>
&lt;script type="text/javascript">
    function showpic(o) {
        o = parseInt(o);
        switch (o)
        {
        case 1:
            imgName='pictures/senda.jpg';break;
        case 2:
            imgName='pictures/ns.jpg';break;
        case 3:
            imgName='pictures/zr.jpg';break;
        case 4:
            imgName='pictures/dt.jpg';break;
        case 5:
            imgName='pictures/rs.jpg';break;
        }
        var DivImage = document.getElementById('DivImg');
        var DisplayImg = document.getElementById('IdImg');
        DisplayImg.src=imgName;
        DivImage.style.visibility="visible";
    }
</script>
</head>
<body>
<form name="form2" method="post" action="race.php?action=race">
<table border="1"><td>Who do you wanna race?<br>
<font size="1">Hint:You get 100 points for racing this class</font></td></table>
    <select size=5 name="bike" onchange="showpic(this.options[this.selectedIndex].value)">
    <option value="1">Derbi Senda 50</option>
    <option value="2">Honda NS 50 R</option>
    <option value="3">Suzuki ZR 50</option>
    <option value="4">Yamaha DT 50 R</option>
    <option value="5">Aprilia RS 50</option>
    </select><br>
    <input type=submit value=Race>  
    <div id="DivImg" style="position:relative;top:-90px;left:150px;z-index:20;width:25px;height:25px;visibility:hidden;text-align:center;"><img id="IdImg"></div>
</td>
</tr>
</form>

</body>
</html>

<?php
}
?>
<form method=post action='login_success.php'>
                         <input type=submit value='Go to main!'></form>
Go to the top of the page
 
+Quote Post
Miles
post Feb 21 2008, 06:45 PM
Post #2


Advanced Member
Group Icon

Group: [HOSTED]
Posts: 177
Joined: 25-December 07
Member No.: 27,129



I'm not sure, but judging from your code, this could be caused by not having the session_start() function at the top of the code. Put it to the top and post here with any more issues. Or, it could be that config.php has session_start() already in it and you're having it again, which causes warnings. If all else fails, it dosen't seem much more than a warning, so you could possibly have error_reporting(0); in it, which I believe stops warnings from coming up.
Go to the top of the page
 
+Quote Post
Eggie
post Feb 21 2008, 07:07 PM
Post #3


Advanced Member
Group Icon

Group: Members
Posts: 130
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



i put it up and it's ok...
now i have another problem...
this is my logout script...
CODE
<?
session_start();
session_destroy();
?>

and this is another part in other script(login_success)...
CODE
if(!session_is_registered(myusername)){
header("location:main_login.php");
}

when i go to my logout script and after that i go to the "login_success.php" script it just prints out just as i didnt go to my logout script.. what could cause the problem?

EDIT:btw this is my "login_check.php" script

CODE
<?php
include("style.css");
include("config.php");
// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
$_SESSION['views'] = $_POST['myusername'];
}
else {
echo "Wrong Username or Password";
}
?>


This post has been edited by Eggie: Feb 21 2008, 07:23 PM
Go to the top of the page
 
+Quote Post
Feelay
post Feb 21 2008, 08:30 PM
Post #4


Kinda N00B
Group Icon

Group: Members
Posts: 212
Joined: 13-January 08
From: Sweden
Member No.: 27,579



I think I know whats wrong.

You have registered a session in a way I've never used. But i checked the php manual, and according to that one, you must unregister registered sessions.

You can do that by typing something like this:
CODE
session_unregister("myusername");

You must include this code (and unregister mypassword), in the logout script. here is the link for the phpmanual:
session_unregister php manual
Go to the top of the page
 
+Quote Post
Eggie
post Feb 21 2008, 08:37 PM
Post #5


Advanced Member
Group Icon

Group: Members
Posts: 130
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



QUOTE(Feelay @ Feb 21 2008, 09:30 PM) *
I think I know whats wrong.

You have registered a session in a way I've never used. But i checked the php manual, and according to that one, you must unregister registered sessions.

You can do that by typing something like this:
CODE
session_unregister("myusername");

You must include this code (and unregister mypassword), in the logout script. here is the link for the phpmanual:
session_unregister php manual

how do you register sessions??can u put it here please??

EDIT:and unregister...please copy those codes here...

This post has been edited by Eggie: Feb 21 2008, 08:40 PM
Go to the top of the page
 
+Quote Post
Feelay
post Feb 21 2008, 08:41 PM
Post #6


Kinda N00B
Group Icon

Group: Members
Posts: 212
Joined: 13-January 08
From: Sweden
Member No.: 27,579



QUOTE
CODE
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
$_SESSION['views'] = $_POST['myusername'];
}
This is your code.. Look at this:

QUOTE
CODE
session_register("myusername");
session_register("mypassword");


This is were you have registered them. now in the logoutscript, you should unregister them.
Go to the top of the page
 
+Quote Post
Eggie
post Feb 21 2008, 08:46 PM
Post #7


Advanced Member
Group Icon

Group: Members
Posts: 130
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



QUOTE(Feelay @ Feb 21 2008, 09:41 PM) *
This is your code.. Look at this:
This is were you have registered them. now in the logoutscript, you should unregister them.

this is my logout script
CODE
<?
session_start();

session_unregister("myusername");
?>

Go to the top of the page
 
+Quote Post
Feelay
post Feb 21 2008, 08:51 PM
Post #8


Kinda N00B
Group Icon

Group: Members
Posts: 212
Joined: 13-January 08
From: Sweden
Member No.: 27,579



You said this is your logout script:

QUOTE
CODE
<?
session_start();
session_destroy();
?>


And I said that you should try to change it to this wink.gif:

CODE
<?
session_start();
session_unregister("mypassword");
session_unregister("myusername");
session_unset();
session_destroy();
?>


But eggie. remember. as I told You.. I have NEVER ever used session_regiter and session_unregister, so I dont know if I am using session_unregister the right way..

Maybe it is:



CODE
<?
session_start();
session_unregister($mypassword);
session_unregister($myusername);
session_unset();
session_destroy();
?>

I don't know. try both.. but I know that the fault is from there.
Go to the top of the page
 
+Quote Post
Eggie
post Feb 21 2008, 09:13 PM
Post #9


Advanced Member
Group Icon

Group: Members
Posts: 130
Joined: 19-January 08
From: Zagreb/Croatia
Member No.: 27,735



QUOTE(Feelay @ Feb 21 2008, 09:51 PM) *
But eggie. remember. as I told You.. I have NEVER ever used session_regiter and session_unregister

thats why i asked u to copy that code where you register and unregister in ur scripts
Go to the top of the page
 
+Quote Post
Feelay
post Feb 21 2008, 09:18 PM
Post #10


Kinda N00B
Group Icon

Group: Members
Posts: 212
Joined: 13-January 08
From: Sweden
Member No.: 27,579



I don't understand.. tongue.gif
did the code I gave you work, or didn't you try?
Go to the top of the page
 
+Quote Post

3 Pages V   1 2 3 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Trainable Anti-spam Filter Script(3)
  2. Php Script To Download File From Another Site(9)
  3. How Do I Create And Write To Files?(4)
  4. Need Help With A PHP - MySQL Registration Script(13)
  5. What Would Make A Good Registration Script?(4)
  6. Auto Responder Script(6)
  7. Blog Script?(5)
  8. Installed A PR Checker Script - But Not Working Correctly(6)
  9. How To Delete File Using PHP Shell Script(3)
  10. Online Multiplayer Chess Script(2)
  11. Automated File Structure Creation Script(3)
  12. Authentication Script(1)
  13. Login Script(5)
  14. Please Help (php Join Script)(5)
  15. Automatic/remote Php Script Execution(9)
  1. Something Wrong With This Script?(9)
  2. Automated Product Suggestion Script(2)
  3. Run A Script When Expires A Session(6)
  4. Php Script Help(1)
  5. SQL Doesn't Connect In PHP Script(19)
  6. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  7. Password Recovery Script(6)
  8. Login Script(8)
  9. Free Forum Hosting Type Script Help!(2)
  10. Script Request(2)
  11. Make A Script Run Even If No User Is Online(6)
  12. Php Login Script(0)
  13. Myspacetv Download Php Script Help(6)


 



- Lo-Fi Version Time is now: 30th August 2008 - 07:43 AM