matt.sisto Posted March 18, 2009 Share Posted March 18, 2009 Hello, I have sorted out my login, which when checked header:location to cal.php. For some when it reaches cal.ph it redirects to loginform1.php but if I change the header location it is ok? logincheck1.php: <?php session_start(); require "dbconn2.php"; //Using the function mysql_real_escape_string() AFTER a connection //has been established will clean incoming variables and prevent //users from tampering with your SQL by inserting some of their own $email_address = mysql_real_escape_string($_POST['email_address']); $passwd = mysql_real_escape_string($_POST['passwd']); $id = mysql_real_escape_string($_POST['id']); if($id == 'client') { $sql = "SELECT * FROM client WHERE email_address='".$email_address ."' AND passwd='".$passwd."'"; $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error()); $row = mysql_fetch_row($result); } else if($id == 'consultant') { $sql = "SELECT * FROM consultant WHERE email_address='".$email_address ."' AND passwd='".$passwd."'"; $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error()); $row = mysql_fetch_row($result); } else if($id == 'organisation') { $sql = "SELECT * FROM organisation WHERE email_address='".$email_address ."' AND passwd='".$passwd."'"; $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error()); $row = mysql_fetch_row($result); } else{ echo 'Incorrect type'; } if ($row != null) { $_SESSION['username'] = $row['first_name']; header("Location: index.html"); exit(); } else { header("Location: loginform1.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>logincheck1.php</title> </head> <body> </body> </html> cal.php <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: loginform1.php"); echo ("Welcome $session[username]"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <div align="center"> <?php if ((!isset($_GET["Month"])) && (!isset($_GET["Year"]))) { $Month = date("m"); $Year = date("Y"); } else { $Month = $_GET["Month"]; $Year = $_GET["Year"]; } $Timestamp = mktime(0,0,0,$Month,1,$Year); $MonthName = date("F", $Timestamp); ?> <?php echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\">"; echo "<tr><td colspan=\"7\" align=\"left\">Calendar Table for $MonthName, $Year</td></tr>"; echo "<tr bgcolor=\"#999999\">"; $daysOfWeek = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); foreach ($daysOfWeek as $value) { echo "<td align=\"center\"><strong><font color=\"#ffffff\">$value</font></strong></td>"; } echo "</tr>"; $MonthStart = date("w", $Timestamp); if ($MonthStart == 0) { // if the month starts on a Sunday $MonthStart = 7; } $LastDay = date("d", mktime(0,0,0,$Month+1, 0, $Year)); $StartDate = -$MonthStart; for ($k=1;$k<=6;$k++){ //print six rows for six possible weeks echo"<tr>"; for ($j=1;$j<=7;$j++){ //seven columns per row $StartDate++; if($StartDate < $LastDay) { //blank calendar space if($StartDate > 0) { echo"<td>$StartDate</td> \n"; } else { echo"<td bgcolor=\"#eeeeee\"></td> \n"; } } elseif (($StartDate <=1) && ($StartDate >= $LastDay)) { //date goes here if($StartDate >= 0) { echo"<td>$StartDate</td> \n"; } } } echo"</tr>"; } //End Table Row echo "</table>"; ?> <hr width="200"> <form action="cal.php" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="GET" > <?php echo "<select name=\"Month\">"; for($m=1;$m<=12;$m++){ $selected = ""; $longDate = date("F", mktime(0,0,0,$m,1,$Year)); if ($Month==$m){ $selected = "selected "; } echo "<option value=\"$m\" $selected>$longDate</option> \n"; } echo "</select>"; echo "<select name=\"Year\">"; for($y=date;$y<=date+1;){ $selected = ""; $longDate = date("Y", mktime(0,0,0,1,1,$y)); if ($Year==$y){ $selected = "selected \n"; } echo "<option value=\"$y\" $selected>$longDate</option> \n"; } echo "</select>"; ?> <input type="submit" value="go"> </form> </div> </body> </html> Probably very simple but I can't work it out. Appreciate any help. Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/ Share on other sites More sharing options...
waynew Posted March 18, 2009 Share Posted March 18, 2009 Hi, Where are you redirecting to cal.php? Also, you're redirecting to a page called index.html before? HTML files cant contain php code (most of the time), so obviously you're not able to continue the session using session_start(); This could mean that you're session is being lost as soon as your code redirects to index.html if ($row != null){ $_SESSION['username'] = $row['first_name']; header("Location: index.html"); exit(); } else{ header("Location: loginform1.php"); exit(); } Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/#findComment-787655 Share on other sites More sharing options...
matt.sisto Posted March 18, 2009 Author Share Posted March 18, 2009 if ($row != null){ $_SESSION['username'] = $row['first_name']; header("Location: cal.php"); exit(); } else{ header("Location: loginform1.php"); exit(); } Sorry My mistake, it works when the Header location is index.html, but when I change it to cal.php it just redirects to loginform1.php? Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/#findComment-787679 Share on other sites More sharing options...
waynew Posted March 18, 2009 Share Posted March 18, 2009 Well, for one thing you're referencing the first name column as $row['first_name'] when you had used mysql_fetch_row to get your resultset. WHen you use mysql_fetch_row, the result is returned as an array, starting from 0 to the number of columns in your db. So, if you have a user_id column first, that will be $row[0]. If your first name column comes second, it will be $row[1], and so forth. Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/#findComment-787681 Share on other sites More sharing options...
matt.sisto Posted March 18, 2009 Author Share Posted March 18, 2009 but there doesn't seem to be a problem when the header location is to a different page, just whenever it contains the calender script. ??? Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/#findComment-787687 Share on other sites More sharing options...
matt.sisto Posted March 18, 2009 Author Share Posted March 18, 2009 http://salmonsreach.org/index.html login: [email protected] password: password waynewex if you go to the url, then login, I have a link to the cal page, but when activated u are just redirected to the login. ??? Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/#findComment-787691 Share on other sites More sharing options...
matt.sisto Posted March 18, 2009 Author Share Posted March 18, 2009 select client at the login form Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/#findComment-787692 Share on other sites More sharing options...
waynew Posted March 18, 2009 Share Posted March 18, 2009 Try logincheck1.php: <?php session_start(); require "dbconn2.php"; //Using the function mysql_real_escape_string() AFTER a connection //has been established will clean incoming variables and prevent //users from tampering with your SQL by inserting some of their own $email_address = mysql_real_escape_string($_POST['email_address']); $passwd = mysql_real_escape_string($_POST['passwd']); $id = mysql_real_escape_string($_POST['id']); if($id == 'client') { $sql = "SELECT * FROM client WHERE email_address='".$email_address ."' AND passwd='".$passwd."'"; $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error()); $row = mysql_fetch_assoc($result); } else if($id == 'consultant') { $sql = "SELECT * FROM consultant WHERE email_address='".$email_address ."' AND passwd='".$passwd."'"; $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error()); $row = mysql_fetch_assoc($result); } else if($id == 'organisation') { $sql = "SELECT * FROM organisation WHERE email_address='".$email_address ."' AND passwd='".$passwd."'"; $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error()); $row = mysql_fetch_assoc($result); } else{ echo 'Incorrect type'; } if ($row != null) { $_SESSION['username'] = $row['first_name']; header("Location: index.html"); exit(); } else { header("Location: loginform1.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>logincheck1.php</title> </head> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/#findComment-787695 Share on other sites More sharing options...
matt.sisto Posted March 18, 2009 Author Share Posted March 18, 2009 http://www.salmonsreach.org/loginform1.php Waynewex its not the login form that has the issue, its the cal.php that does, it just doesn't work with the session, it keeps redirecting to the loginform? ??? Link to comment https://forums.phpfreaks.com/topic/149980-solved-session-login-header-loaction-issues/#findComment-787710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.