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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.