chandler Posted October 22, 2010 Share Posted October 22, 2010 Hi, im getting alot of errors like so Deprecated: Function session_is_registered() is deprecated time to update some files, can you guys pls help im rubbish with PHP guess thats why I waited so long to update. here is the code I need to change checklogin.php // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:index.php"); } index.php <? session_start(); /*if(!session_is_registered(myusername)){ header("location:main_login.php"); }*/ ?> index.php (display username stuff) <?php if(session_is_registered(myusername)){ ?> Welcome: <?= $_SESSION['myusername'] ?><?php } ?> index.php (edit content stuff) <?php $file = file_get_contents('content/menu_header_a.txt', 'r'); if(session_is_registered(myusername)){ ?><a href="javascript:open4()"><?php echo $file ?></a><?php } else { echo $file; }?> Many thanks for any and all your help with this one. if you could keep it simple please like ( replace this with this ) . thanks Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/ Share on other sites More sharing options...
MatthewJ Posted October 22, 2010 Share Posted October 22, 2010 // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername'] = $myusername; $_SESSION['mypassword'] = $mypassword; header("location:index.php"); } <?php session_start(); if(!isset($_SESSION['myusername'])){ header("location:main_login.php"); } ?> <?php if(isset($_SESSION['myusername'])) { ?> Welcome: <?= $_SESSION['myusername'] ?><?php } ?> <?php $file = file_get_contents('content/menu_header_a.txt', 'r'); if(isset($_SESSION['myusername'])){ ?><a href="javascript:open4()"><?php echo $file ?></a><?php } else { echo $file; }?> Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125254 Share on other sites More sharing options...
chandler Posted October 22, 2010 Author Share Posted October 22, 2010 Thanks Matthew worked like a charm Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125267 Share on other sites More sharing options...
chandler Posted October 22, 2010 Author Share Posted October 22, 2010 I spoke to soon, I am having problems with this part, I only want to have to login to edit content I dont want to have to login just to view the page, but when I use this it keeps directing me to main_login.php <?php session_start(); if(!isset($_SESSION['myusername'])){ header("location:main_login.php"); } ?> thanks for your help. Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125367 Share on other sites More sharing options...
chandler Posted October 23, 2010 Author Share Posted October 23, 2010 any idea, anyone? Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125481 Share on other sites More sharing options...
MatthewJ Posted October 23, 2010 Share Posted October 23, 2010 I uncommented it when I fixed it... I thought you probably had it commented out while it was having problems <?php session_start(); /*if(!isset($_SESSION['myusername'])){ header("location:main_login.php"); }*/ ?> Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125507 Share on other sites More sharing options...
chandler Posted October 23, 2010 Author Share Posted October 23, 2010 Yes I did try that too, but then it for some reason wont let me edit the content. How can I make sure that I am logged? is there a bit of code that can confirm the loggin/ session is active? Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125549 Share on other sites More sharing options...
revraz Posted October 23, 2010 Share Posted October 23, 2010 Set a variable to TRUE if the session username is set, then read that variable to show/hide your edit feature. Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125566 Share on other sites More sharing options...
chandler Posted October 23, 2010 Author Share Posted October 23, 2010 way over my head can you please show me how to do that..thanks Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125620 Share on other sites More sharing options...
chandler Posted October 23, 2010 Author Share Posted October 23, 2010 can anyone explain this to me please Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125698 Share on other sites More sharing options...
chandler Posted October 24, 2010 Author Share Posted October 24, 2010 this is really strange it was working fine untill I changed <? to <?php in the logout.php even when I changed it back it wouldnt work again. and ideas anyone? Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125955 Share on other sites More sharing options...
Pikachu2000 Posted October 24, 2010 Share Posted October 24, 2010 Post your code in its current form . . . Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1125965 Share on other sites More sharing options...
chandler Posted October 25, 2010 Author Share Posted October 25, 2010 index.php <?php session_start(); /*if(!isset($_SESSION['myusername'])){ (I have tried this with and with out /* */ ) header("location:main_login.php"); }*/ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> <script type="text/javascript" src="js/ckeditor/ckeditor.js"></script> <script type="text/javascript" src="js/content.js"></script> <title>Table_Menu</title> <script type="text/javascript" src="jquery-1.2.3.js"></script> <script language="javascript"> function logout() { alert("You are now logged out."); } </script> </head> <body> <div class="wrap"> <div class="header"></div> <div id="navi"></div> <span id="access"> <a href="main_login.php">Login</a> | <a href="logout.php" onclick="logout();">Logout</a> <?php if(isset($_SESSION['myusername'])) { ?> Welcome: <?= $_SESSION['myusername'] ?><?php } ?></span> <div class="content"> <table id="report"> <tr> <th>header</th> <th></th> <th class="menu_header"><?php $file = file_get_contents('content/menu_header_a.txt', 'r'); if(isset($_SESSION['myusername'])){ ?><a href="javascript:open4()"><?php echo $file ?></a><?php } else { echo $file; }?></th> </tr> <tr> <td colspan="5"> <h4>Additional information</h4> <ul> <li></li> </ul> </td> </tr> </table> </div><!-- end content --> </div> <!-- end wrap --> </body> </html> logout.php <?php session_start(); session_destroy(); header("location:index.php"); ?> checklogin.php <?php ob_start(); $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername'] = $myusername; $_SESSION['mypassword'] = $mypassword; header("location:index.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Thanks! Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1126206 Share on other sites More sharing options...
Pikachu2000 Posted October 25, 2010 Share Posted October 25, 2010 You should be developing with display_errors = On, and error_reporting = E_ALL in your php.ini file checklogin.php doesn't have a call to session_start(). Is that a standalone script, or does it get include()d in another script? Don't use stripslashes() on form data without first checking to see if magic_quotes_gpc = On (although it's better to disable magic_quotes_gpc, IMO) You don't have any logic in place to make sure the query executed successfully before trying to use mysql_num_rows() Link to comment https://forums.phpfreaks.com/topic/216576-help-with-login-system-please/#findComment-1126244 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.