shebbycs Posted November 22, 2011 Share Posted November 22, 2011 Login.php <?php session_start(); mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $username = $_POST['username']; $password = $_POST['pass']; if (isset($_POST["submit"])) { $log = "SELECT * FROM regis WHERE username = '$username'"; $login = mysql_query($log); $row = mysql_fetch_array($login); $number = mysql_num_rows($login); if ($number == 0) { print "That user does not exist in our database. <a href=registration.php><input type='button' value='Register'></a>"; } if ($number > 0) { if ($password == $row['password']) { $_SESSION['username'] = $row['username']; $_SESSION['userlevel'] = $row['userlevel']; $_SESSION['is_logged_in'] == 1; if($_SESSION['userlevel']==1) { $_SESSION['is_logged_in'] == 1; echo "<meta http-equiv='refresh' content='0; url=form2.php'>" ; } else if($_SESSION['userlevel']==0) { echo "<meta http-equiv='refresh' content='0; url=registration.php'>"; } } } } else { ?> <html> <head> <script type="text/javascript"> function a() { var x = document.login.username.value; var y = document.login.pass.value; if(x==""&& y=="") { alert("Please insert all message!"); return false; } if(x=="") { alert("Please insert an username!"); return false; } if(y=="") { alert("Please insert an password!"); return false; } } </script> </head> <body> <table border="0"> <form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return a()"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td> <td><input type="text" name="username" maxlength="40"></td></tr> <tr><td>Password:</td> <td><input type="password" name="pass" maxlength="50"></td></tr> <tr><td><input type="submit" name="submit" value="Register"></a></td> <td><input type="submit" name="submit" value="Login"></td></tr> </form> </body> <?php } ?> </html> after im redo my code and after im login there nothign happen but only blank page im wondering why Quote Link to comment https://forums.phpfreaks.com/topic/251625-modified-login-post-but-after-modified-its-is-blank-page/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 22, 2011 Share Posted November 22, 2011 after login try viewing the source, if you see the meta tags appears, that means something is not right with your meta tags. try to force display error at the start of the code. Quote Link to comment https://forums.phpfreaks.com/topic/251625-modified-login-post-but-after-modified-its-is-blank-page/#findComment-1290465 Share on other sites More sharing options...
shebbycs Posted November 22, 2011 Author Share Posted November 22, 2011 after login try viewing the source, if you see the meta tags appears, that means something is not right with your meta tags. try to force display error at the start of the code. yeah yo rite my new code for login.php is <?php session_start(); mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $username = $_POST['username']; $password = $_POST['pass']; if (isset($_POST["submit"])) { $log = "SELECT * FROM regis WHERE username = '$username'"; $login = mysql_query($log); $row = mysql_fetch_array($login); $number = mysql_num_rows($login); if ($number == 0) { print "That user does not exist in our database. <a href=registration.php><input type='button' value='Register'></a>"; } if ($number > 0) { $_SESSION['username'] = $row['username']; $_SESSION['userlevel'] = $row['userlevel']; if($_SESSION['userlevel']==1) { $_SESSION['is_logged_in'] == 1; header("Location: form2.php"); } else if($_SESSION['userlevel']== 0) { header("Location: registration.php"); } } } else { ?> <html> <head> <script type="text/javascript"> function a() { var x = document.login.username.value; var y = document.login.pass.value; if(x==""&& y=="") { alert("Please insert all message!"); return false; } if(x=="") { alert("Please insert an username!"); return false; } if(y=="") { alert("Please insert an password!"); return false; } } </script> </head> <body> <table border="0"> <form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return a()"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td> <td><input type="text" name="username" maxlength="40"></td></tr> <tr><td>Password:</td> <td><input type="password" name="pass" maxlength="50"></td></tr> <tr><td><input type="submit" name="submit" value="Register"></a></td> <td><input type="submit" name="submit" value="Login"></td></tr> </form> </body> <?php } ?> </html> Form2.php <?php session_start(); if (!isset($_SESSION['is_logged_in'])) { header("Location:chatframe.php"); die(); // just to make sure no scripts execute } ?> <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $message=$_POST['message']; $a=$_SESSION['username']; if(isset($_POST['submit'])) //if submit button push has been detected { if(strlen($message)>1) { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "You IP is banned from posting."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$a','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } ?> <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <form name="smile" method="post" action="form2.php" onSubmit="return a()" > Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt="" onClick="addsmiley('')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt="" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <input type='submit' name='submit' value='Send' class='biasa' ></form> <br> <br> </body> </html> now my problem is all header works perfectly but when user level is 1 its should direct to form2.php as im had declared session login is one but in form2.php its reidrect to chatframe.php as it show my session login is not 1 Quote Link to comment https://forums.phpfreaks.com/topic/251625-modified-login-post-but-after-modified-its-is-blank-page/#findComment-1290496 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 23, 2011 Share Posted November 23, 2011 please remember that you have to clear your sessions everytime you changes the code if no the session wouldn't be empty and is set. hope below might help if (!isset($_SESSION['is_logged_in']) || empty($_SESSION['is_logged_in'])) { Quote Link to comment https://forums.phpfreaks.com/topic/251625-modified-login-post-but-after-modified-its-is-blank-page/#findComment-1290711 Share on other sites More sharing options...
Adam Posted November 23, 2011 Share Posted November 23, 2011 FYI ZulfadlyAshBurn, empty() performs an isset() check first. So this: if (!isset($_SESSION['is_logged_in']) || empty($_SESSION['is_logged_in'])) { Will always evaluate to the same as this: if (empty($_SESSION['is_logged_in'])) { Quote Link to comment https://forums.phpfreaks.com/topic/251625-modified-login-post-but-after-modified-its-is-blank-page/#findComment-1290714 Share on other sites More sharing options...
shebbycs Posted November 24, 2011 Author Share Posted November 24, 2011 When im check back the if else statment it is exactly went to right away but when im trying to echoing back the $_SESSION LOG IN ACTUALLY it does not has value im wondering why and for that matter it cannot going to form2.php Quote Link to comment https://forums.phpfreaks.com/topic/251625-modified-login-post-but-after-modified-its-is-blank-page/#findComment-1290852 Share on other sites More sharing options...
shebbycs Posted November 24, 2011 Author Share Posted November 24, 2011 When im check back the if else statment it is exactly went to right away but when im trying to echoing back the $_SESSION LOG IN ACTUALLY it does not has value im wondering why and for that matter it cannot going to form2.php if ($number > 0) { $_SESSION['username'] = $row['username']; $_SESSION['userlevel'] = $row['userlevel']; if($_SESSION['userlevel']==1) { $_SESSION['is_logged_in'] == 1; header("Location: form2.php"); } else if($_SESSION['userlevel']== 0) { header("Location: registration.php"); } } this code even im had also put the "$_SESSION['is_logged_in'] == 1;" outside if else userlevel statement and then i put $d= $_SESSION['is_logged_in'] == 1; and im echoing back but it is nothing im thinks something wrong in session is login Quote Link to comment https://forums.phpfreaks.com/topic/251625-modified-login-post-but-after-modified-its-is-blank-page/#findComment-1290855 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.