SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
Aug 29, 2009, 23:43 #1
- Join Date
- Jul 2006
- Location
- New Zealand
- Posts
- 1,300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
session and php cookies not working together
I am not sure what i have done but for some reason my members area is a blank page i have tried to make the file alittle bit neat and cleaner for you guys.
and it doesnt show a blank page not sure exactly why you can see a demo of what i mean when i view the page at my testing url located at http://bccms.info/new/console.php
the login is demo for username and password here is my code for my problem.
Code PHP:include("functions.php"); $msg_pass=""; session_start(); error_reporting(E_ALL); $msg_user=""; require("dbconnect.php"); //session stuff if(isset($_SESSION['user'])) { // include("dbcoonect.php"); $gQuery="SELECT * FROM members WHERE username='".$_SESSION['user']."'"; //excute the query $rs=mysqli_query($con,$gQuery); if(!$rs) { echo "Error:Failed to executing query".mysqli_error($con); } else { $count=$rs->num_rows; if($count>0) { $data=$rs->fetch_assoc(); $user=$data['username']; } } else { } // } else { //start of cookies if(isset($_COOKIE['user'])) { // include("dbcoonect.php"); $gQuery="SELECT * FROM members WHERE username='".$_COOKIE['user']."'"; //excute the query $rs=mysqli_query($con,$gQuery); if(!$rs) { echo "Error:Failed to executing query".mysqli_error($con); } else { $count=$rs->num_rows; if($count>0) { $data=$rs->fetch_assoc(); $user=$data['username']; } } // } else { // echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\">"; exit; // } //start of console code $gQuery="SELECT * FROM members WHERE username='".$user."'"; //excute the query $rs=mysqli_query($con,$gQuery); if(!$rs) { $dbError="Error:Failed to executing query".mysqli_error($con); } else { $count=$rs->num_rows; if($count>0) { $data=$rs->fetch_assoc(); $disable=$data['disable']; } } if($data['disable']=="0") { echo "Your Clan Account Has been Disabled"; } $gQuery="SELECT * FROM members WHERE username='".$user."'"; //excute the query $rs=mysqli_query($con,$gQuery); if(!$rs) { $dbError="Error:Failed to executing query".mysqli_error($con); } else { $count=$rs->num_rows; if($count>0) { $data=$rs->fetch_assoc(); $username=$data['username']; $rank=$data['rank']; $email=$data['email']; $aim=$data['aim']; $msn=$data['msn']; $recruitedby=$data['Recruitedby']; $joineddate=$data['joineddate']; $disable=$data['disable']; $logindays=$data['logindays']; $web=$data['web']; } } if($data['disable']=="1") { //Start of Non Disabled Members $rmt = $_SERVER["REMOTE_ADDR"]; if($rmt) { $pQuery="update members SET ips = \"$rmt\" WHERE username='".$user."'"; $result=mysqli_query($con,$pQuery); if(!$result) { echo "Error:".mysqli_connect_errno(); echo "<br/>Error2:".mysqli_error($con); } else { echo ""; } } $lQuery="SELECT * FROM Members WHERE username='".$user."'"; $rs=mysqli_query($con,$lQuery); if(!$rs) { $dbError="Error:Failed to executing query".mysqli_error($con); } else { $count=$rs->num_rows; if($count>0) { $data=$rs->fetch_assoc(); $username=$data['username']; $rank=$data['rank']; $email=$data['email']; $aim=$data['aim']; $msn=$data['msn']; $recruitedby=$data['Recruitedby']; $joineddate=$data['joineddate']; $disable=$data['disable']; $logindays=$data['logindays']; $web=$data['web']; $joineddate2=$data['joineddate2']; } } echo ""; switch(true) { case date('G')<13: echo "Good Morning $username"; break; case date('G')<18: echo "Good Afternoon $username"; break; case date('G')<25: echo "Good Evening $username"; break; } echo "<br/>The Time is: "; echo date("g:i a"); echo "";?> <style type="text/css"> .closed { display: none; } </style> <script type="text/javascript"> makeContainer = function(h2id, divid) { var h2 = document.getElementById(h2id); var div = document.getElementById(divid); h2.onclick = function() { div.className = div.className == "open" ? "closed" : "open"; } } makeContainer("profile", "profile-container"); </script> <h2 id="profile">Members</h2> <div id="profile-container" class="open"> <table width="390" border="1" align="center"> <tr> <th colspan="2"> <?php echo "Your Profile";?></th> </tr> </table> <?php //Start of Displaying Profile in Console ?><table> <tr><font size=\"10px\"><td><? echo "Member";?></td> <td><? echo ""; echo get_rank_by_id($rank); echo " ".$user."";?></td> </tr> <tr> <td><? echo "Email";?></td> <td><? echo "".$data['email']."";?></td> </tr> <tr> <td><? echo "Recruited By:";?></td> <td><? echo "".$data['Recruitedby']."";?></td> </tr> <tr> <td><? echo "Date Joined";?></td> <td><? echo "".$joineddate2."";?></td> </tr> <tr> <td>Days in Clan:</td> <td><?php $days=calcDays($username,$joineddate); if($days>=30 && $days<=67) { echo "1 Month In Clan"; } if($days>=68 && $days<=98) { echo "2 Months In Clan"; } if($days>=99 && $days<=128) { echo "3 Months In Clan"; } if($days>=129 && $days<=159) { echo "4 Months In Clan"; } if($days>=160 && $days<=189) { echo "5 Months In Clan"; } if($days>=190 && $days<=220) { echo "6 Months In Clan"; } if($days>=221 && $days<=251) { echo "7 Months In Clan"; } if($days>=252 && $days<=281) { echo "8 Months In Clan"; } if($days>=282 && $days<=312) { echo "9 Months In Clan"; } if($days>=313 && $days<=342) { echo "10 Months In Clan"; } if($days>=343 && $days<=373) { echo "11 Months In Clan"; } if($days>=374 && $days<=403) { echo "1 Year"; } //Year 1 if($days>=404 && $days<=431) { echo "1 Year and 1 Month In Clan"; } if($days>=432 && $days<=431) { echo "1 Year and 2 Months In Clan"; } if($days>=463 && $days<=492) { echo "1 Year and 3 Months In Clan"; } if($days>=493 && $days<=523) { echo "1 Year and 4 Months In Clan"; } if($days>=524 && $days<=553) { echo "1 Year and 5 Months In Clan"; } if($days>=554 && $days<=584) { echo "1 Year and 6 Months In Clan"; } if($days>=585 && $days<=615) { echo "1 Year and 7 MonthsIn Clan"; } if($days>=616 && $days<=645) { echo "1 Year and 8 Months In Clan"; } if($days>=646 && $days<=676) { echo "1 Year and 9 Months In Clan"; } if($days>=677 && $days<=706) { echo "1 Year and 10 Months In Clan"; } if($days>=707 && $days<=747) { echo "1 Year and 11 Months In Clan"; } // if($days==748 && $days<=777) { echo "2 Years"; } //Second Year if($days>=778 && $days<=806) { echo "1 Year and 1 Month In Clan"; } if($days>=806 && $days<=837) { echo "1 Year and 2 Months In Clan"; } if($days>=837 && $days<=867) { echo "1 Year and 3 Months In Clan"; } if($days>=867 && $days<=898) { echo "1 Year and 4 Months In Clan"; } if($days>=898 && $days<=928) { echo "1 Year and 5 Months In Clan"; } if($days>=928 && $days<=959) { echo "1 Year and 6 Months In Clan"; } if($days>=959 && $days<=990) { echo "1 Year and 7 Months In Clan"; } if($days>=990 && $days<=1020) { echo "1 Year and 8 Months In Clan"; } if($days>=1020 && $days<=1051) { echo "1 Year and 9 Months In Clan"; } if($days>=1051 && $days<=1080) { echo "1 Year and 10 Months In Clan"; } if($days>=1081 && $days<=1121) { echo "1 Year and 11 Months In Clan"; } // if($days>=1122 && $days<=1495) { echo "3 Years"; } if($days>=1496 && $days<=1869) { echo "4 Years"; } if($days>=1870) { echo "5 Years"; } //echo "You have been in the clan for $days Days";?></td> </tr> </table></div><?php //End of Display Console require("dbconnect.php"); $lQuery="SELECT * FROM members WHERE username='".$user."'"; $rs=mysqli_query($con,$lQuery); if(!$rs) { $dbError="Error:Failed to executing query".mysqli_error($con); } else { $count=$rs->num_rows; if($count>0) { $data=$rs->fetch_assoc(); $username=$data['username']; $rank=$data['rank']; $consoletype=$data['consoletype']; } } if($data['consoletype']=="1") { require("consoletype1.inc.php"); } else { require("consoletype2.inc.php"); } include("dbconnect.php"); $cQuery="select * from news where status='Members'"; $rs=mysqli_query($con,$cQuery); if(!$rs) { echo "Error:".mysqli_error($con); } else { $count=$rs->num_rows; if($count>0) { echo "<br/><br/><table border='0'> <tr> <th>Clan Names</th> </tr>"; while($data=$rs->fetch_assoc()) { echo "<tr> <td>Posted by:".$data['author']."</td> <td>Subject:".$data['subject']."</td> </tr> <tr> <td colspan='2'>".$data['content']."</td> </tr>"; } echo "</table><br/><br/>"; } else { echo "<br/><br/>No Clan News At the Moment"; } //end of console end } //End of Console // } include("footer.inc.php");
can you help me fix my php code and tell me why its displaying a blank page?
any help would be good thanks.
-
Aug 30, 2009, 00:05 #2
- Join Date
- Jan 2005
- Location
- heaven
- Posts
- 953
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
error_reporting(E_ALL); should come before everything else and make sure you use ini_set('display_errors', 1) in conjunction with it. From the looks of it the error could be coming from the functions.php file. The blank page tells me that either the error comes before your call to error_reporting, or you have a problem of a function redefinition. Place the following on line one and two.
PHP Code:ini_set('display_errors',1);
error_reporting(E_ALL | E_STRICT);
Creativity knows no other restraint than the
confines of a small mind. - Me
Geekly Humor
Oh baby! Check out the design patterns on that framework!
-
Aug 30, 2009, 04:20 #3
- Join Date
- Jul 2006
- Location
- New Zealand
- Posts
- 1,300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i am still getting a blank page for some reason heres an upated code.
PHP Code:<?php
ini_set('display_errors',1);
error_reporting(E_ALL | E_STRICT);
include("header.inc.php");
if($_GET['cmd']=="view")
{
//
//
}
$msg_pass="";
$msg_user="";
require("dbconnect.php");
//session stuff
echo "hi";
if(isset($_SESSION['user']))
{
//
include("dbcoonect.php");
$gQuery="SELECT * FROM members WHERE username='".$_SESSION['user']."'";
//excute the query
$rs=mysqli_query($con,$gQuery);
if(!$rs)
{
echo "Error:Failed to executing query".mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
$data=$rs->fetch_assoc();
$user=$data['username'];
}
}
//
}
else
{
//start of cookies
if(isset($_COOKIE['user']))
{
//
include("dbcoonect.php");
$gQuery="SELECT * FROM members WHERE username='".$_COOKIE['user']."'";
//excute the query
$rs=mysqli_query($con,$gQuery);
if(!$rs)
{
echo "Error:Failed to executing query".mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
$data=$rs->fetch_assoc();
$user=$data['username'];
}
}
//
}
else
{
//
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\">";
exit;
//
}
//start of console code
$gQuery="SELECT * FROM members WHERE username='".$user."'";
//excute the query
$rs=mysqli_query($con,$gQuery);
if(!$rs)
{
$dbError="Error:Failed to executing query".mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
$data=$rs->fetch_assoc();
$disable=$data['disable'];
}
}
if($data['disable']=="0")
{
echo "Your Clan Account Has been Disabled";
}
$gQuery="SELECT * FROM members WHERE username='".$user."'";
//excute the query
$rs=mysqli_query($con,$gQuery);
if(!$rs)
{
$dbError="Error:Failed to executing query".mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
$data=$rs->fetch_assoc();
$username=$data['username'];
$rank=$data['rank'];
$email=$data['email'];
$aim=$data['aim'];
$msn=$data['msn'];
$recruitedby=$data['Recruitedby'];
$joineddate=$data['joineddate'];
$disable=$data['disable'];
$logindays=$data['logindays'];
$web=$data['web'];
}
}
if($data['disable']=="1")
{
//Start of Non Disabled Members
$rmt = $_SERVER["REMOTE_ADDR"];
if($rmt)
{
$pQuery="update members SET ips = \"$rmt\" WHERE username='".$user."'";
$result=mysqli_query($con,$pQuery);
if(!$result)
{
echo "Error:".mysqli_connect_errno();
echo "<br/>Error2:".mysqli_error($con);
}
else
{
echo "";
}
}
$lQuery="SELECT * FROM Members WHERE username='".$user."'";
$rs=mysqli_query($con,$lQuery);
if(!$rs)
{
$dbError="Error:Failed to executing query".mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
$data=$rs->fetch_assoc();
$username=$data['username'];
$rank=$data['rank'];
$email=$data['email'];
$aim=$data['aim'];
$msn=$data['msn'];
$recruitedby=$data['Recruitedby'];
$joineddate=$data['joineddate'];
$disable=$data['disable'];
$logindays=$data['logindays'];
$web=$data['web'];
$joineddate2=$data['joineddate2'];
}
}
echo "";
switch(true)
{
case date('G')<13:
echo "Good Morning $username";
break;
case date('G')<18:
echo "Good Afternoon $username";
break;
case date('G')<25: echo "Good Evening
$username";
break;
}
echo "<br/>The Time is: ";
echo date("g:i a");
echo "";?>
<style type="text/css">
.closed { display: none; }
</style>
<script type="text/javascript">
makeContainer = function(h2id, divid) {
var h2 = document.getElementById(h2id);
var div = document.getElementById(divid);
h2.onclick = function() {
div.className = div.className == "open" ? "closed" : "open";
}
}
makeContainer("profile", "profile-container");
</script>
<h2 id="profile">Members</h2>
<div id="profile-container" class="open">
<table width="390" border="1" align="center">
<tr>
<th colspan="2">
<?php echo "Your Profile";?></th>
</tr>
</table>
<?php
//Start of Displaying Profile in Console
?><table>
<tr><font size=\"10px\"><td><? echo "Member";?></td>
<td><? echo "";
echo get_rank_by_id($rank);
echo " ".$user."";?></td>
</tr>
<tr>
<td><? echo "Email";?></td>
<td><? echo "".$data['email']."";?></td>
</tr>
<tr>
<td><? echo "Recruited By:";?></td>
<td><? echo "".$data['Recruitedby']."";?></td>
</tr>
<tr>
<td><? echo "Date Joined";?></td>
<td><? echo "".$joineddate2."";?></td>
</tr>
<tr>
<td>Days in Clan:</td>
<td><?php
$days=calcDays($username,$joineddate);
if($days>=30 && $days<=67)
{
echo "1 Month In Clan";
}
if($days>=68 && $days<=98)
{
echo "2 Months In Clan";
}
if($days>=99 && $days<=128)
{
echo "3 Months In Clan";
}
if($days>=129 && $days<=159)
{
echo "4 Months In Clan";
}
if($days>=160 && $days<=189)
{
echo "5 Months In Clan";
}
if($days>=190 && $days<=220)
{
echo "6 Months In Clan";
}
if($days>=221 && $days<=251)
{
echo "7 Months In Clan";
}
if($days>=252 && $days<=281)
{
echo "8 Months In Clan";
}
if($days>=282 && $days<=312)
{
echo "9 Months In Clan";
}
if($days>=313 && $days<=342)
{
echo "10 Months In Clan";
}
if($days>=343 && $days<=373)
{
echo "11 Months In Clan";
}
if($days>=374 && $days<=403)
{
echo "1 Year";
}
//Year 1
if($days>=404 && $days<=431)
{
echo "1 Year and 1 Month In Clan";
}
if($days>=432 && $days<=431)
{
echo "1 Year and 2 Months In Clan";
}
if($days>=463 && $days<=492)
{
echo "1 Year and 3 Months In Clan";
}
if($days>=493 && $days<=523)
{
echo "1 Year and 4 Months In Clan";
}
if($days>=524 && $days<=553)
{
echo "1 Year and 5 Months In Clan";
}
if($days>=554 && $days<=584)
{
echo "1 Year and 6 Months In Clan";
}
if($days>=585 && $days<=615)
{
echo "1 Year and 7 MonthsIn Clan";
}
if($days>=616 && $days<=645)
{
echo "1 Year and 8 Months In Clan";
}
if($days>=646 && $days<=676)
{
echo "1 Year and 9 Months In Clan";
}
if($days>=677 && $days<=706)
{
echo "1 Year and 10 Months In Clan";
}
if($days>=707 && $days<=747)
{
echo "1 Year and 11 Months In Clan";
}
//
if($days==748 && $days<=777)
{
echo "2 Years";
}
//Second Year
if($days>=778 && $days<=806)
{
echo "1 Year and 1 Month In Clan";
}
if($days>=806 && $days<=837)
{
echo "1 Year and 2 Months In Clan";
}
if($days>=837 && $days<=867)
{
echo "1 Year and 3 Months In Clan";
}
if($days>=867 && $days<=898)
{
echo "1 Year and 4 Months In Clan";
}
if($days>=898 && $days<=928)
{
echo "1 Year and 5 Months In Clan";
}
if($days>=928 && $days<=959)
{
echo "1 Year and 6 Months In Clan";
}
if($days>=959 && $days<=990)
{
echo "1 Year and 7 Months In Clan";
}
if($days>=990 && $days<=1020)
{
echo "1 Year and 8 Months In Clan";
}
if($days>=1020 && $days<=1051)
{
echo "1 Year and 9 Months In Clan";
}
if($days>=1051 && $days<=1080)
{
echo "1 Year and 10 Months In Clan";
}
if($days>=1081 && $days<=1121)
{
echo "1 Year and 11 Months In Clan";
}
//
if($days>=1122 && $days<=1495)
{
echo "3 Years";
}
if($days>=1496 && $days<=1869)
{
echo "4 Years";
}
if($days>=1870)
{
echo "5 Years";
}
//echo "You have been in the clan for $days Days";?></td>
</tr>
</table></div><?php
//End of Display Console
require("dbconnect.php");
$lQuery="SELECT * FROM members WHERE username='".$user."'";
$rs=mysqli_query($con,$lQuery);
if(!$rs)
{
$dbError="Error:Failed to executing query".mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
$data=$rs->fetch_assoc();
$username=$data['username'];
$rank=$data['rank'];
$consoletype=$data['consoletype'];
}
}
if($data['consoletype']=="1")
{
require("consoletype1.inc.php");
}
else
{
require("consoletype2.inc.php");
}
include("dbconnect.php");
$cQuery="select * from news where status='Members'";
$rs=mysqli_query($con,$cQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
$count=$rs->num_rows;
if($count>0)
{
echo "<br/><br/><table border='0'>
<tr>
<th>Clan Names</th>
</tr>";
while($data=$rs->fetch_assoc())
{
echo "<tr>
<td>Posted by:".$data['author']."</td>
<td>Subject:".$data['subject']."</td>
</tr>
<tr>
<td colspan='2'>".$data['content']."</td>
</tr>";
}
echo "</table><br/><br/>";
}
else
{
echo "<br/><br/>No Clan News At the Moment";
}
//end of console end
}
//End of Console //
}
include("footer.inc.php");
?>
-
Aug 30, 2009, 18:06 #4
- Join Date
- Jul 2006
- Location
- New Zealand
- Posts
- 1,300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ive i have decided to re-write my code but problem now is my php code is thinking i am not logged in here is my php code
for my console php page.
PHP Code:session_start();
include("header.inc.php");
require("dbconnect.php");
//session stuff
if(!isset($_SESSION['user']) || $_COOKIE['user'])
{
echo "Please Login";
}
else
{
//
echo "Your Logged in";//
}
PHP Code:<?php
include("header.inc.php");
session_start();
require("dbconnect.php");
error_reporting(E_ALL);
$msg_pass="";
$msg_user="";
if($_POST['username'] && $_POST['password'])
{
include("dbconnect.php");
$username = mysqli_real_escape_string($con,stripslashes(trim($_POST['username'])));
$password = mysqli_real_escape_string($con,stripslashes(trim($_POST['password'])));
$cQuery="SELECT * FROM members WHERE username='".$username."' AND Password='".$password."'";
$con;
$rm=$_POST['rememberme'];
echo $cQuery;
$rs=mysqli_query($con,$cQuery);
if(!$rs)
{
echo "Unable to excute the query:".mysqli_error($con);
}
else
{
$count=mysqli_num_rows($rs);
echo $count;
if($count>0)
{
$data=mysqli_fetch_assoc($rs);
if($data['password']=$password)
{
//For Rembmer me
//echo "hi";
if($rm="On")
{
setcookie("user",$username,time()-7200);
//
$today=date("Ymd");
include("dbconnect.php");
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1'
WHERE username='".$_COOKIE['user']."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "<font color=".$fontcolor.">Logged in as: ".$_COOKIE['user']."<br/>";
echo "<font color=".$fontcolor.">Please Wait while we log you in</font>";
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=console.php?cmd=view\">";
//
}
if(!$rm="On")
{
//
if(isset($_SESSION['user']))
{
//
$_SESSION['user']=$username;
$today=date("Ymd");
include("dbconnect.php");
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1'
WHERE username='".$_SESSION['user']."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "<font color=".$fontcolor.">Logged in as: ".$_SESSION['user']."<br/>";
echo "<font color=".$fontcolor.">Please Wait while we log you in</font>";
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=console.php?cmd=view\">";
//
}
//
//
}
//if Session
}
else
{
$msg_pass="Wrong Password,Please Try again<br>\n";
$rmt = $_SERVER["REMOTE_ADDR"];
$today=date("F j,Y,g:i a");
if($rmt || $today)
{
$pQuery="insert into failedlogins values('','$username','$password','$rmt','$today')";
$result=mysqli_query($con,$pQuery);
if(!$result)
{
echo "<font color=".$fontcolor.">Error:".mysqli_connect_errno();
echo "<br/><font color=".$fontcolor.">Error2:".mysqli_error($con);
}
else
{
echo "<font color=".$fontcolor.">Your Ip Address has been Logged!</font>";
}
}
}
}
else
{
$msg_user="Wrong Username,Please Try again<br>\n";
$rmt = $_SERVER["REMOTE_ADDR"];
$today=date("F j,Y,g:i a");
if($rmt || $today)
{
$pQuery="insert into failedlogins values('','$username','$password','$rmt','$today')";
$result=mysqli_query($con,$pQuery);
if(!$result)
{
echo "<font color=".$fontcolor.">Error:".mysqli_connect_errno();
echo "<br/><font color=".$fontcolor.">Error2:".mysqli_error($con);
}
else
{
echo "<font color=".$fontcolor.">Your Ip Address has been Logged!</font>";
}
}
}
}
}
include("footer.inc.php");
?>
-
Sep 2, 2009, 03:07 #5
- Join Date
- Jul 2006
- Location
- New Zealand
- Posts
- 1,300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
regarding my post over on webdeveloper.com forums i get this error now
ive made changes to the code and i tried to print out all cookies if there are any and this is what i get back
Array ( [PHPSESSID] => 3309abd6a5905b33b6bf44291ae1cd4d )
what does that exactly mean?
also i printed out what the user is doing and by looks of it the login is thinking that the user is logging in as a session not via a cookie
this is what i get back from echoing cookies and sessions
Array ( [PHPSESSID] => 3309abd6a5905b33b6bf44291ae1cd4d )
session info is
Array ( [user] => demo )
heres an updated php code.
PHP Code:<?php
//
if($_POST['login'])
{
include("dbconnect.php");
$username = mysqli_real_escape_string($con,stripslashes(trim($_POST['username'])));
$password = mysqli_real_escape_string($con,stripslashes(trim($_POST['password'])));
$cQuery="SELECT * FROM members WHERE username='".$username."' AND Password='".$password."'";
$con;
$rs=mysqli_query($con,$cQuery);
if(!$rs)
{
echo "Unable to excute the query:".mysqli_error($con);
}
else
{
$count=mysqli_num_rows($rs);
if($count>0)
{
$data=mysqli_fetch_assoc($rs);
if($data['password']=$password)
{
//For Rembmer me
ob_start();
session_start();
setcookie("user",$username,time()-7200);
ob_flush();
//sleep for 5 seconds
sleep(5);
include("header.inc.php");
error_reporting(E_ALL);
ini_set("error_reporting", 2047);
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
if(isset($_POST['rememberme']))
{
//
print_r($_COOKIE);
echo "<br/> session info is<br/>";
print_r($_SESSION);
ob_end_flush();
if(isset($_COOKIE['user']))
{
//
$today=date("Ymd");
include("dbconnect.php");
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1'
WHERE username='".$_COOKIE['user']."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "<font color=".$fontcolor.">Logged in as: ".$_COOKIE['user']."<br/>";
echo "<font color=".$fontcolor.">Please Wait while we log you in</font>";
//echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=console.php\">";
//
}
}
else
{
//
$_SESSION['user']=$username;
$today=date("Ymd");
include("dbconnect.php");
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1'
WHERE username='".$_SESSION['user']."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "<font color=".$fontcolor.">Logged in as: ".$_SESSION['user']."<br/>";
echo "<font color=".$fontcolor.">Please Wait while we log you in</font>";
//echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=console.php\">";
//
}
}
else
{
$msg_pass="Wrong Password,Please Try again<br>\n";
$rmt = $_SERVER["REMOTE_ADDR"];
$today=date("F j,Y,g:i a");
if($rmt || $today)
{
$pQuery="insert into failedlogins values('','$username','$password','$rmt','$today')";
$result=mysqli_query($con,$pQuery);
if(!$result)
{
echo "<font color=".$fontcolor.">Error:".mysqli_connect_errno();
echo "<br/><font color=".$fontcolor.">Error2:".mysqli_error($con);
}
else
{
echo "<font color=".$fontcolor.">Your Ip Address has been Logged!</font>";
}
}
}
}
else
{
$msg_user="Wrong Username,Please Try again<br>\n";
$rmt = $_SERVER["REMOTE_ADDR"];
$today=date("F j,Y,g:i a");
if($rmt || $today)
{
$pQuery="insert into failedlogins values('','$username','$password','$rmt','$today')";
$result=mysqli_query($con,$pQuery);
if(!$result)
{
echo "<font color=".$fontcolor.">Error:".mysqli_connect_errno();
echo "<br/><font color=".$fontcolor.">Error2:".mysqli_error($con);
}
else
{
echo "<font color=".$fontcolor.">Your Ip Address has been Logged!</font>";
}
}
}
}
/**/
}
include("footer.inc.php");
?>
Warning: Cannot modify header information - headers already sent by (output started at /home/bchostin/public_html/bccms/new/login.php:36) in /home/bchostin/public_html/bccms/new/login.php on line 39 now i get this thats its printing this on the screen when it should be either one.
so now why is it still including cookies when the above code is saying sessions and stuff shudnt it be displaying the php cookies information when i print it out?
thanks,William
-
Sep 2, 2009, 14:45 #6
- Join Date
- Jul 2006
- Location
- New Zealand
- Posts
- 1,300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i have it kind of sorted but now i have another problem that has risen
PHP Code:if(isset($_POST['rememberme']) && !empty($_POST['rememberme']))
{
//
echo "cookies are ";
print_r($_COOKIE);
if(isset($_COOKIE['user']))
{
//
$today=date("Ymd");
include("dbconnect.php");
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1'
WHERE username='".$_COOKIE['user']."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "<font color=".$fontcolor.">Logged in as: ".$_COOKIE['user']."<br/>";
echo "<font color=".$fontcolor.">Please Wait while we log you in</font>";
//echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=console.php\">";
//
}
}
else
{
//
ob_start();
session_start();
ob_flush();
//sleep for 5 seconds
sleep(5);
error_reporting(E_ALL);
ini_set("error_reporting", 2047);
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
echo "<br/> session info is<br/>";
print_r($_SESSION);
ob_end_flush();
$_SESSION['user']=$username;
$today=date("Ymd");
include("dbconnect.php");
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1'
WHERE username='".$_SESSION['user']."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "<font color=".$fontcolor.">Logged in as: ".$_SESSION['user']."<br/>";
echo "<font color=".$fontcolor.">Please Wait while we log you in</font>";
//echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=console.php\">";
//
}
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/bchostin/public_html/bccms/new/login.php:26) in /home/bchostin/public_html/bccms/new/login.php on line 65
on lines 25 and 26 i have this
PHP Code:setcookie("user",$username,time()-7200);
ob_flush();
PHP Code:ob_start();
session_start();
Any ideas on how i can fix this,
Thanks,William
-
Sep 3, 2009, 02:57 #7
- Join Date
- Jul 2006
- Location
- New Zealand
- Posts
- 1,300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the php cookies are definately not being sent.
heres the function of the php code i have placed the php function at the top of the script.
PHP Code:$u=$_SERVER['SERVER_NAME'];
//setcookie('user',$username,time()-7200);
echo $_COOKIE['user'];
setcookie("user",$username,time()+7200,"/",$u,1);
if(isset($_COOKIE['user']))
{
//
echo "cookies are ";
$today=date("Ymd");
include("dbconnect.php");
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1'
WHERE username='".$_COOKIE['user']."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "Logged in as: ".$_COOKIE['user']."<br/>";
echo "Please Wait while we log you in<";
//echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=console.php\">";
/*
$today=date("Ymd");
include("dbconnect.php");
$dQuery="UPDATE members SET
LastedLogin='$today',signons=signons+1,onlinestatus='1'
WHERE username='".$username."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "<font color=".$fontcolor.">Logged in as: ".$username."<br/>";
echo "<font color=".$fontcolor.">Please Wait while we log you in</font>";
*/
//
}
Bookmarks