简体   繁体   中英

Where to add the PHP script and MYSQL Dump code in the LAMP server?

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]; 
    } 
?> 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM