php - Major Issue with Session and Login -
ok ive been having major problem site. whats going on i'm going page page not maintaining session. here couple source codes on same directory. ok have index modal box contains iframe login.php , logout.php. logs me in once go different page doesn't carry session , when click login says im logged in , has session. how can add cookies website find confusing.
just snippets:
part of header.php goes on every page
<?php session_start(); if($_session["username"]) { ?> <div style="display: inline-block; font-size: 14px; padding-left: 20px;">hello <?php echo $_session['username']; ?>
login.php
<?php session_start(); require_once('connections/main.php'); if($_session['username']) { echo '<div class="error_message">attention! you, '.$_session['username'].' logged in.</div>'; echo "<br />"; echo "go <a target='top' href='index.php'>back</a> page viewing before this.</li>"; exit(); } ... database funcctions go here add session if($rowcheck > 0) { while($row = mysql_fetch_array($result)) { // start session , register variable session_start(); $_session['username'] = $user; //session_register('username'); echo '<script> parent.document.location.href = "index.php"; </script>'; }
logout.php
<?php session_start(); ?> <?php if($_session['username']) { session_unset(); session_destroy(); header("location: index.php"); } else { header("location: index.php"); } ?>
found out wrong has problem. must make sure every url user goes http://website.com or http://www.website.com not mixed. cannot have different pages both of these or sessions disappear. because www stored in www/website/ , not website/
Comments
Post a Comment