Styles2304 Posted April 19, 2008 Share Posted April 19, 2008 This code is identical to another login.php for the main website. This is a sub site if you will but for some reason, the $_SESSION variables don't carry over the way they do on the main site. I know the server has them enabled because, like I said, on the main website this works fine. If I test it using some echo's and what not . . . it definitely the information because I can spit it right back out however, it won't store the date in the database properly and won't keep the variables once the user is forwarded. Here is the code: <?php //Starting the session and user authentication session_start(); include "conn.inc.php"; if (isset($_POST['submit'])) { $query = "SELECT * FROM Profile " . "WHERE Username = '" . $_POST['username'] . "' " . "AND Password = '" . $_POST['password'] . "'"; $result = mysql_query($query,$link) or die(mysql_error()); if (mysql_num_rows($result) == 1) { while ($row = mysql_fetch_array($result)) { $_SESSION['user_index'] = $row['IndexNo']; $_SESSION['user_fname'] = $row['FirstName']; $_SESSION['user_lname'] = $row['LastName']; } $LastLog = date('Y-m-d'); $query = "UPDATE Profile SET LastLog = " . $LastLog . " WHERE IndexNo = " . $_SESSION['user_index'] . ""; mysql_query($query,$link) or die(mysql_error()); header("Refresh: 1; URL=profile.php"); echo "You are being logged in<br>"; echo "(If your browser doesn't support this, <a href=\"profile.php\">click here</a>)"; } else { ?> <html> <head> <title>Zero Gravity</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <LINK REL=StyleSheet HREF="style.css" TYPE="text/css"> </head> <body background="images/main_background.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <center> Invalid Username and/or Password <br><br> <form action="login.php" method="post"> <input type="hidden" name="redirect" value="<?php echo $_POST['redirect']; ?>"> Username: <input type="text" name="username"><br><br> Password: <input type="password" name="password"><br><br> <input type="submit" name="submit" value="Login"> </form> <br> <font size="2pt"> If you have forgotten your password, send an e-mail to <a href="mailto:styles2304@ma.rr.com" class="white">Styles2304@ma.rr.com</a> <br> with the subject of Login Information. </font> </center> </body> </html> <?php } } else { if (isset($_GET['redirect'])) { $redirect = $_GET['redirect']; } else { $redirect = "profile.php"; } ?> <html> <head> <title>Zero Gravity</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <LINK REL=StyleSheet HREF="style.css" TYPE="text/css"> </head> <body background="images/main_background.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <center> Login below by entering your username and password. <br><br> <form action="login.php" method="post"> <input type="hidden" name="redirect" value="<?php echo $_POST['redirect']; ?>"> Username: <input type="text" name="username"><br><br> Password: <input type="password" name="password"><br><br> <input type="submit" name="submit" value="Login"> </form> <br> <font size="2pt"> If you have forgotten your password, send an e-mail to <a href="mailto:styles2304@ma.rr.com" class="white">Styles2304@ma.rr.com</a> <br> with the subject of Login Information. </font> </center> </body> </html> <?php } ?> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 19, 2008 Share Posted April 19, 2008 Does it have a different domain name? For instance, the main site is "mainsite.com" and the sub site is "subsite.mainsite.com". If so, php, and apache, treat them as totally different sites. Each one will have a different session id for the same user. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted April 20, 2008 Author Share Posted April 20, 2008 no it's mainsite.com/subsite/subsite.php. But it shouldn't matter because all the pages that it's NOT carrying over to are within the subsite directory so it's subsite/login.php . . . subsite/index.php . . . subsite/whatever.php. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted April 20, 2008 Author Share Posted April 20, 2008 Anyone? Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 20, 2008 Share Posted April 20, 2008 Have you tried a different browser/platform? Maybe for some reason your browser is not receiving/sending the session cookie or PHP_SESSID variable. Is the only place that you access the $_SESSION variable on those 3 lines where you set the indexno, firstname and last name? You could be accidentally overwriting the $_SESSION variable contents some other place. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 20, 2008 Share Posted April 20, 2008 1.) Are you sure they're being set in the first place? 2.) I assume you have session_start() at the top of the second page? Quote Link to comment Share on other sites More sharing options...
ap_ Posted April 20, 2008 Share Posted April 20, 2008 if is a free domain try setting the cookies to low in the privacy tab Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted April 20, 2008 Author Share Posted April 20, 2008 dptr: I use session variables on the main website and they work fine so the browser/platform is NOT that problem. Also, there are only two pages right now, the login page and the profile page. The only place the session variables are referenced on the profile page is where I try to retrieve information from the database based on the $_SESSION['user_index']. So, they are definitely not overwritten. Another side note, the session variables can't even be echoed on the profile page so for some reason they're not getting there after the re-direct. GingerRobot: Check the code, I define the session variables that I need. Your second question, no, I don't have session_start() at the top of the second page because I don't need it . . . the session has already started by that point. ap_: not a free domain and this all works on the main site . . . something is messed up here. Quote Link to comment Share on other sites More sharing options...
monkeypaw201 Posted April 20, 2008 Share Posted April 20, 2008 I don't have session_start() at the top of the second page because I don't need it . . . the session has already started by that point. Can you do us the courtesy of adding it and telling us what happens? Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 20, 2008 Share Posted April 20, 2008 What is this 'second page'? Is that an included file? Do you understand that you have to use session_start() for each page that gets requested by the browser? Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted April 20, 2008 Author Share Posted April 20, 2008 Ok well lol monkeypaw201 . . . yeah. I didn't add it but I realized that I left off the authentication include which had session_start() in it so yeah, I'm an idiot. Thank you. Quote Link to comment Share on other sites More sharing options...
monkeypaw201 Posted April 20, 2008 Share Posted April 20, 2008 No problem, thats what this forum is for,, it has happened many a time, when i post something not working and its a missing comma or some little stupid mistake Happens to everyone Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.