pcw Posted April 1, 2009 Share Posted April 1, 2009 I have these four pages. One of these is a login page, which is ok, the login_chk.php file checks that the username and password are correct, and then it redirects to the logged in page. The problem I am having is the session is not passing from login_chk.php to loggedin.php, and therefore, it is just redirecting to the login.php page again. These are the pages and the directories they are located with. /sitebuilder/templates/members/login.php <?php include ("../common/header.php"); print '<form action="../../sb.php?cmd=logchk" method="post"> <input type="hidden" name="action" value="login"> <table width="300" border="1" cellpadding="0" cellspacing="0"> <tr> <td width="5" height="5"></td> <td></td> <td width="5"></td> </tr> <tr> <td></td> <td><table width="90%" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"><h2>Log On<br /> </h2> <hr /></td> </tr> <tr> <td align="right">Username:</td> <td><input type="text" name="username"></td> </tr> <tr> <td align="right">Password:</td> <td><input type="password" name="password"></td> </tr> <tr> <td align="right"> </td> <td align="left"><input type="submit" name="submit" value="submit"></td> </tr> <tr></tr> </table> <br /> </td> <td></td> </tr> <tr> <td height="5"></td> <td></td> <td></td> </tr> </table> </form> <br /> <table width="300" border="1" cellpadding="0" cellspacing="0"> <tr> <td width="5" height="5" ></td> <td> </td> <td width="5"></td> </tr> <tr> <td></td> <td><table width="90%" border="0" cellpadding="5" cellspacing="0"> <tr> <td>Not a member? </td> </tr> <tr> <td><h2><a href="./sb.php">Join Up </a></h2></td> </tr> </table> </td> <td></td> </tr> <tr> <td height="5"></td> <td></td> <td></td> </tr> </table> <p></p></td> <td width="20"> </td> <td valign="top"><br /> <br /> <h2 align="left">Sitebuilder login page </h2> <p align="justify"> Thank you for registering. Please login to access the members area.</p> <p align="justify">You are free to modify this page as you wish.</p> <p align="justify">Please follow the instruction guide, when altering the code. </p> </td> </tr> </table> '; include ("../common/footer.php"); ?> /sitebuilder/templates/members/loggedin.php <?php session_start(); if($_SESSION['valid'] == true) { print ' <table width="700" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td valign="top"> <table width="300" border="1" cellpadding="0" cellspacing="0"> <tr> <td width="5" height="5"></td> <td></td> <td width="5"></td> </tr> <tr> <td></td> <td><table width="90%" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"><h2 class=style2>Members Area<br /> </h2> <hr /></td> </tr> <tr><td class=style3>Your login has been successful</td></tr> <tr></tr> </table> <br /> </td> <td></td> </tr> <tr> <td height="5"></td> <td></td> <td></td> </tr> </table> </form> <br /> <table width="300" border="1" cellpadding="0" cellspacing="0"> <tr> <td width="5" height="5" ></td> <td> </td> <td width="5"></td> </tr> <tr> <td></td> <td><table width="90%" border="0" cellpadding="5" cellspacing="0"> <tr> <td class=style3>Visit another secure page. </td> </tr> <tr> <td><h2><a href="./loggedin2.php">Go to page 2</a></h2></td> </tr> </table> </td> <td></td> </tr> <tr> <td height="5"></td> <td></td> <td></td> </tr> </table> <p></p></td> <td width="20"> </td> <td valign="top"><br /> <br /> <h2 align="left" class=style2>Sitebuilder registration page </h2> <p align="justify" class=style3> You have successfully registered. If you wish to logout,<a href="logout.php">click here</a></p> <p align="justify" class=style3>You are free to modify this page as you wish.</p> <p align="justify" class=style3>Please follow the instruction guide, when altering the code. </p> </td> </tr> </table> </body> </html>'; include_once("../common/footer.php"); } else { print "<META http-equiv='refresh' content='3;URL=login.php'>"; } ob_end_flush(); ?> /sitebuilder/data/library/login_chk.php <?php function login_chk() { include("data/required.php"); session_start(); $_SESSION['valid'] = false; if (isset($_POST['submit'])) { mysql_connect('localhost', $dbuser, $dbpass) or die(mysql_error()); mysql_select_db( $db) or die(mysql_error()); $username = mysql_real_escape_string($_POST['username']); $password_encoded = mysql_real_escape_string(base64_encode($_POST['password'])); if ($result = mysql_query("SELECT username, password, verified FROM profiles WHERE username='$username' AND password='$password_encoded' AND verified='yes'")) { if (mysql_num_rows($result) > 0) { $_SESSION['valid'] = true; header( 'Location: templates/members/loggedin.php' ) ; # Change this file to the page of your choice }else { echo "Login not successful."; login(); } }else{ echo "SQL Error: " . mysql_error(); } } } ?> sitebuilder/sb.php <?php include_once("data/library/add_user.php"); include_once("data/library/email_reg.php"); include_once("data/library/login.php"); include_once("data/library/pin_chk.php"); include_once("data/library/verified.php"); include_once("data/library/dbconnect.php"); include_once("data/library/form_validation.php"); include_once("data/library/login_chk.php"); include_once("data/library/unverified.php"); include_once("data/library/pin.php"); $cmd = $_GET['cmd']; if ($cmd=="") { $cmd = "validate"; } switch($cmd) { # This defines the start of page 1 case "validate": form_validation(); break; # Beginning of page 3 case "pinver": # Calls the function that checks that the entered validation PIN matches that in the database, before calling other # functions. (See includes.php and instructions). pin_chk(); # Ends the page break; case "logchk": # Calls the function that checks whether the username and password used to login, match those in the database. # Also calls other function if successful. (See includes.php and instructions). login_chk(); # Ends the page break; } ?> Any help will be much appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/152129-passing-session-problem/ Share on other sites More sharing options...
revraz Posted April 1, 2009 Share Posted April 1, 2009 Try moving session_start(); at the start of your code instead of having it in the function. Link to comment https://forums.phpfreaks.com/topic/152129-passing-session-problem/#findComment-798974 Share on other sites More sharing options...
pcw Posted April 1, 2009 Author Share Posted April 1, 2009 I tried this but still no luck Link to comment https://forums.phpfreaks.com/topic/152129-passing-session-problem/#findComment-798982 Share on other sites More sharing options...
PFMaBiSmAd Posted April 1, 2009 Share Posted April 1, 2009 What does a phpinfo() statement show for the session.cookie_path setting? Have you solved the header errors, because until you do, the session won't start and won't exist when you go to another page. Link to comment https://forums.phpfreaks.com/topic/152129-passing-session-problem/#findComment-798990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.