ayok Posted December 16, 2007 Share Posted December 16, 2007 Hi, got another problem I've created simple login scripts for my webpage, but I cannot use it on my webserver. Here is the codes for check_login.php: <?php include "connect_db.php"; $login=mysql_query("SELECT * FROM users WHERE username= '$username' AND password='$password'") or die (mysql_error()); $data=mysql_fetch_array($login); if($data[username]==$username AND $data[password]==$password) { session_start(); session_register("nameuser"); session_register("passuser"); $nameuser=$data[username]; $passuser=$data[password]; header("location:index.php"); } else { echo "Failed! you give wrong username and password<BR>"; echo "<a href=form_login.php>try again</a>"; } ?> And ini every page, there are codes: <?php session_start(); if(!empty($nameuser) AND !empty ($passuser)) { do things }else{ echo "You have to login before adding new items<BR>"; echo "<a href=form_login.php>Login</a>"; } The scripts worked on my local server but not on web server. From the information I've got, it doesn't work because use the register_globals. Would anybody help me how I solve this? Thank you, ayok Link to comment https://forums.phpfreaks.com/topic/81901-help-admin-login/ Share on other sites More sharing options...
Trium918 Posted December 16, 2007 Share Posted December 16, 2007 register_globals = off it should allows be off for security reason <?php $username =$_POST['username']; $password =$_POST['password']; ?> Here is a link that will help you http://www.w3schools.com/php/php_post.asp Link to comment https://forums.phpfreaks.com/topic/81901-help-admin-login/#findComment-416109 Share on other sites More sharing options...
revraz Posted December 16, 2007 Share Posted December 16, 2007 Where do you get $username and $password from? If iits a from from another page, then just use POST as the method and add: $username = $_POST['username']; $password = $_POST['password']; $login=mysql_query("SELECT * FROM users WHERE username= '$username' AND password='$password'") or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/81901-help-admin-login/#findComment-416110 Share on other sites More sharing options...
ayok Posted December 16, 2007 Author Share Posted December 16, 2007 Thank you for the reply, guys. I've tried to put those POST codes, but I got the same result which go back to the login page. I've tried to add this: <?php session_start(); $namauser = $_GET['nameuser'];<-- $passuser = $_GET['passuser'];<-- if(!empty($nameuser) AND !empty ($passuser)) { do things }else{ echo "You have to login before adding new items<BR>"; echo "<a href=form_login.php>Login</a>"; } on index.php. But still.. doesn't work. Link to comment https://forums.phpfreaks.com/topic/81901-help-admin-login/#findComment-416116 Share on other sites More sharing options...
Trium918 Posted December 16, 2007 Share Posted December 16, 2007 Thank you for the reply, guys. I've tried to put those POST codes, but I got the same result which go back to the login page. I've tried to add this: <?php session_start(); $namauser = $_GET['nameuser'];<-- $passuser = $_GET['passuser'];<-- if(!empty($nameuser) AND !empty ($passuser)) { do things }else{ echo "You have to login before adding new items<BR>"; echo "<a href=form_login.php>Login</a>"; } on index.php. But still.. doesn't work. You are placing the code in the wrong location. Try placing it where revraz told you to place it. Link to comment https://forums.phpfreaks.com/topic/81901-help-admin-login/#findComment-416122 Share on other sites More sharing options...
Grego Posted December 16, 2007 Share Posted December 16, 2007 You said "$namauser", which I assume you don't want to. Link to comment https://forums.phpfreaks.com/topic/81901-help-admin-login/#findComment-416123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.