Jump to content

Help Admin Login


ayok

Recommended Posts

Hi, got another problem  ;D

 

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.