kclark Posted July 6, 2010 Share Posted July 6, 2010 I have a login form that I use for my video conference login. I setup a username and pwd on my end and send it to the user to be involved. I have the script running on another site running php4, but I can't get it to work on my new site and it is running php5. I don't know if php version has anything to do with it, but I think so. This is my login form and login check script all on one page. I will submit the form, but it just shows the form again without any errors or anything. If no errors, it should go to my page with my video, but the form acts like it is being refreshed. <?php // Use session variable on this page. This function must put on the top of page. session_start(); ////// Logout Section. Delete all session variable. unset($_SESSION['username']); $message=""; ////// Login Section. $Login=$_POST['Login']; if($Login == "Login"){ // If clicked on Login button. $username=$_POST['username']; $password=$_POST['password']; // Encrypt password with md5() function. // Get a database object // Connect database. $host="host.com"; // Host name. $db_user="user"; // MySQL username. $db_password="pwd"; // MySQL password. $database="dbname"; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); // Check matching of username and password. $result=mysql_query("select * from videologin where username='$username' and password='$password' and live='1' LIMIT 1"); if(mysql_num_rows($result)!='0'){ // If match. $_SESSION['username']; // Create session username. //session_register("username"); // Create session username. header("location:live.php"); // Re-direct to main.php exit; }else{ // If not match. $message="--- Incorrect Username, Password, or You Are Trying To View At An Incorrect Time ---"; } } // End Login authorize check. ?> <br> <p> <p align="center"><? echo $message; ?></p> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table align="center"> <p align="center"> Please Login below to view our live video, using the name and password given to you.<tr> </p> <td>User : </td> <td><input name="username" type="text" id="username" ></td> </tr> <tr> <td>Password : </td> <td><input name="password" type="password" id="password" ></td> </tr> </table> <p align="center"> <input name="Login" type="submit" id="Login" value="Login" > </p> </form> <p align="center"><b>Please Note</b> that usernames and passwords will not work<br>until approximately 10 minutes prior to service time.</p> Quote Link to comment Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 The only thing I can think of is where you assign the session username. $_SESSION['username']; // Create session username. Change that to: $_SESSION['username'] = $username; // Create session username. The session_register problably set it to "" so if you did not want the username stored in that this would also work: $_SESSION['username'] = ""; // Create session username. Not sure why that would matter though, unless live.php tests for the session username and if it is not set redirects you back to that page. But give that a go. Quote Link to comment Share on other sites More sharing options...
kclark Posted July 6, 2010 Author Share Posted July 6, 2010 here is my page that is brought up if login is correct. <? // You may copy this PHP section to the top of file which needs to access after login. session_start(); // Use session variable on this page. This function must put on the top of page. if(!session_is_registered(username)){ // if session variable "username" does not exist. header("location:http://www.mysite.com/index.php/livelogin"); // Re-direct to index.php ?> <center><?php include "livecode.php"; ?></center> If for any reason you loose your connection, please refresh your browser to reconnect. Quote Link to comment Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 if(!isset($_SESSION['username'])){ // if session variable "username" does not exist. Would be the proper method to do it. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 6, 2010 Share Posted July 6, 2010 if(!session_is_registered(username)){ should be if(!isset($_SESSION['username'])){ session_register() or session_is_registered() are deprecated and should no longer be used. When you want to create a session variable use the $_SESSION superglobal variable, eg $_SESSION['myvar'] = 'somevalue'. Just make sure you're calling session_start at the top of each page before using $_SESSION's Quote Link to comment Share on other sites More sharing options...
kclark Posted July 6, 2010 Author Share Posted July 6, 2010 I fixed that, but still can't get my form to work. Quote Link to comment Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 Perhaps your new setup has short_open_tags removed. Try changing <? to be <?php in both places. If that is the problem, this "should" fix it. But something tells me it is not Also make sure that your error_reporting is set to E_ALL for development and "display_errors" is set to on: <?php error_reporting(E_ALL); ini_set("display_errors", "on"); This will inform you have any errors PHP may be having. Quote Link to comment Share on other sites More sharing options...
kclark Posted July 6, 2010 Author Share Posted July 6, 2010 I get this Notice: A session had already been started - ignoring session_start() in /usr/local/4admin/apache/vhosts/mysite.com/httpdocs/php/livelogin.php on line 6 Here is my updated code. <?php error_reporting(E_ALL); ini_set("display_errors", "on"); // Use session variable on this page. This function must put on the top of page. //session_start(); ////// Logout Section. Delete all session variable. unset($_SESSION['username']); $message=""; ////// Login Section. //$Login=$_POST['Login']; //if($Login == "Login"){ // If clicked on Login button. if(!empty($_POST['Login'])){ $username=$_POST['username']; $password=$_POST['password']; // Encrypt password with md5() function. // Check matching of username and password. $result=mysql_query("select * from videologin where username='$username' and password='$password' and live='1' LIMIT 1"); if(mysql_num_rows($result)!='0'){ // If match. $_SESSION['username'] = $_POST['username']; // Create session username. header("location:http://www.mysite.com/index.php/live"); // Re-direct to main.php exit; }else{ // If not match. $message="--- Incorrect Username, Password, or You Are Trying To View At An Incorrect Time --- } } // End Login authorize check. ?> <br> <p> <p align="center"><? echo $message; ?></p> <form id="form1" name="form1" method="post" action="http://www.mysite.com/index.php/livelogin"> <table align="center"> <p align="center"> Please Login below to view our live video, using the name and password given to you.<tr> </p> <td>User : </td> <td><input name="username" type="text" id="username" ></td> </tr> <tr> <td>Password : </td> <td><input name="password" type="password" id="password" ></td> </tr> </table> <p align="center"> <input name="Login" type="submit" id="Login" value="Login" > </p> </form> <p align="center"><b>Please Note</b> that usernames and passwords will not work<br>until approximately 10 minutes prior to service time.</p> Quote Link to comment Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 You have a syntax error: $message="--- Incorrect Username, Password, or You Are Trying To View At An Incorrect Time ---"; That will fix that syntax error at least. Quote Link to comment Share on other sites More sharing options...
kclark Posted July 7, 2010 Author Share Posted July 7, 2010 i fixed that too. No luck on the form though. Quote Link to comment Share on other sites More sharing options...
kclark Posted July 7, 2010 Author Share Posted July 7, 2010 I am getting this error Notice: A session had already been started - ignoring session_start() 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.