views:

42

answers:

1

Hi,

I dont know if this is the right place to ask this question. But as time is limited and here I have always got the right answers I am asking it away.

I want to setup a login page on a local server so as to communicate with it via android. As time permits, I googled and found out the necessary php script and mySQL code needed for the same. I don't know where to add these code in the local server and connect them. :( (This is mainly for testing purpose as we would develop a website in Django latter on.) Any help would be much appreciated..

    <?php 
    unset($_GET); 

    if( isset($_POST['username']) && isset($_POST['password']) ) { 

        echo '<?xml version="1.0"?>'."\n"; 
        echo "<login>\n"; 

        if (!@mysql_connect('host', 'user', 'pass')) { error(1); } 
        if (!mysql_select_db('database')) { error(2); } 

        if(get_magic_quotes_gpc()) { 
            $login = stripslashes($_POST['username']); 
            $pass  = stripslashes($_POST['password']); 
        } else { 
            $login = $_POST['username']; 
            $pass  = $_POST['password']; 
        } 

        unset($_POST); 

        $kid = login($login, $pass); 
        if($kid == -1) { 
            error(3); 
        } else { 
            printf('    <user id="%d"/>'."\n",$kid); 
        } 

        echo "</login>"; 
    } 

    function error($ec) { 
        printf('    <error value="%d"/>'."\n".'</login>',$ec); 
        die(); 
    } 

    function login($login, $pass) { 
        $select = "SELECT user_id FROM auth_table "; 
        $where = "WHERE username = '%s' AND password = '%s'"; 
        $fixedlogin = mysql_real_escape_string($login); 
        $fixedpass  = mysql_real_escape_string($pass); 
        $query = sprintf($select.$where, $fixedlogin, $fixedpass); 
        $result = mysql_query($query); 
        if(mysql_num_rows($result) != 1) { return -1; }    
        $row = mysql_fetch_row($result); 
        return $row[0]; 
    } 
?> 
+1  A: 

The Webroot (the base folder which is accessed by Apache to serve the website) should be something like /var/www.

The MySQL code needs to be loaded into the MySQL Database to be accessed. You can do that using the MySQL Command Line, or through a package like phpMyAdmin.

This is pretty basic stuff, and should be Google-able with next to no hassle.

Lucanos
I added MYSQL code via phpMyAdmin and also added the php script in the /var/www folder. But when I tried accessing it via browser (http://localhost/login.php) it doesnt show up anything.
primalpop
If you place a simple text file *test.txt* containing something you will recognise (like "Hello World!") in **/var/www** and then attempt to view it using the URL http://localhost/test.txt does it work?If so, then there may be an error in the *login.php* file, if not, then there may be an issue with Apache.Also, the *login.php* file may be showing nothing as it might be experiencing an error but is not displaying it through the browser. (Check out http://au2.php.net/manual/en/function.error-reporting.php and set it to E_ALL in *login.php*.)
Lucanos
I could load the test.php in browser which shows up the php configuration info. I've edited the question and added the login.php file.
primalpop