FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


I need some help please!





darkjoker
Crying or Very sad Ok heres the problem. I have 2 codes so this might take 2 posts so im sorry in advance for double posting. Ok now the problem is that on my site people can register and login wich the register part works fine now when they login it take them to the members page. But i want the members page to be viewed only by logedin members so you have to be loged in to view the page. But i have so far when you login it says continue to members page like it should if you loged in correctly but when when you continue to the members page it says you not loged in like it should if your not loged in. Here is the code to login.php


Code:
<HTML>
<BODY>
<TITLE>Welcome</TITLE>


<BODY bgcolor="#000000" text="#FF0000">
</BODY>
</HTML>


<?php
 

include("config.php");
 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$fetch = "select id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";
 
$qry = mysql_query($fetch)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
 

if ($num_rows <= 0) {
echo "Sorry, there is no username $username with the specified password.<br>";
echo "<a href=index.html>Try again</a>";


exit;
} else {


echo "You are now logged in!<br>";
echo "Continue to the <a href=members.php>members</a> section.";
}
ob_end_flush();
?>




And heres the code to members.php

Code:
<html>
<head><?php
if (!isset($_COOKIE['loggedin'])) die("You are not logged in!");
$mysite_username = $HTTP_COOKIE_VARS["username"];
?>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<a href="index.html" onmouseover="setOverImg('1','');overSub=true;showSubMenu('submenu1','button1');" onmouseout="setOutImg('1','');overSub=false;setTimeout('hideSubMenu(\'submenu1\')',delay);" target=""><img src="buttons/button1up.png" border="0" id="button1" vspace="0" hspace="1"></a><br>
<a href="shop.php" onmouseover="setOverImg('2','');overSub=true;showSubMenu('submenu2','button2');" onmouseout="setOutImg('2','');overSub=false;setTimeout('hideSubMenu(\'submenu2\')',delay);" target=""><img src="buttons/button2up.png" border="0" id="button2" vspace="0" hspace="1"></a><br>
<a href="world.php" onmouseover="setOverImg('3','');overSub=true;showSubMenu('submenu3','button3');" onmouseout="setOutImg('3','');overSub=false;setTimeout('hideSubMenu(\'submenu3\')',delay);" target=""><img src="buttons/button3up.png" border="0" id="button3" vspace="0" hspace="1"></a><br>
<a href="online.php" onmouseover="setOverImg('4','');overSub=true;showSubMenu('submenu4','button4');" onmouseout="setOutImg('4','');overSub=false;setTimeout('hideSubMenu(\'submenu4\')',delay);" target=""><img src="buttons/button4up.png" border="0" id="button4" vspace="0" hspace="1"></a><br>
<a href="buypoints.php" onmouseover="setOverImg('5','');overSub=true;showSubMenu('submenu5','button5');" onmouseout="setOutImg('5','');overSub=false;setTimeout('hideSubMenu(\'submenu5\')',delay);" target=""><img src="buttons/button5up.png" border="0" id="button5" vspace="0" hspace="1"></a><br>
<a href="bank.php" onmouseover="setOverImg('6','');overSub=true;showSubMenu('submenu6','button6');" onmouseout="setOutImg('6','');overSub=false;setTimeout('hideSubMenu(\'submenu6\')',delay);" target=""><img src="buttons/button6up.png" border="0" id="button6" vspace="0" hspace="1"></a><br>
<a href="logout.php" onmouseover="setOverImg('7','');overSub=true;showSubMenu('submenu7','button7');" onmouseout="setOutImg('7','');overSub=false;setTimeout('hideSubMenu(\'submenu7\')',delay);" target=""><img src="buttons/button7up.png" border="0" id="button7" vspace="0" hspace="1"></a><br>
</td></tr></table>



</body
</html>


Anything would be a big help thanks.





mathiaus wrote:

Please do not double post. Use the button instead!

mathiaus
The user page requires $_COOKIE['loggedin'] to be set but your login code doesn't set this so when you login all your actually doing is having your password checked (in your code).

setcookie
Example
Code:
} else {
echo "You are now logged in!<br>";
echo "Continue to the <a href=members.php>members</a> section.";
setcookie("loggedin", true, time()+3600);
}
rfwrangler
You could use sessions as well to do this instead of using a cookie. Remember that some people turn off cookie support for their browsers
darkjoker
ok i added the code that you posted with the cookies and i got this msg

Warning: Cannot modify header information - headers already sent by (output started at /home/darkjoke/domains/jediwars.frih.net/public_html/login.php:13) in /home/darkjoke/domains/jediwars.frih.net/public_html/login.php on line 45
iflash
If you are using sessions make sure that the code for those is o the first place of your script.

<!DOCTYPE HTML PUBLIC
-----sessions part ............ WRONG


-----sessions part ............ OK
<!DOCTYPE HTML PUBLIC
kv
You have to use ob_start() at the beginning of your login.php to use ob_end_flush() at the end. ob_start() is missing in your code.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.