Software Archive
Read-only legacy content
17061 Discussions

Login PHP and PostgreSQL

Gabriel_A_
Beginner
7,359 Views

I'm developing an app where I need implements login, the all data are stored in PostgreSQL database, I'm using PHP and XAMPP as server, but it's not works, an error appears:

Cannot POST /http-services/emulator-webserver/ripple/userapp/x/C/Users/Gabriel.DESKTOP-HUBGD9F/AppData/Local/XDK/xdk-scratchdir/d1b4c333-e5d3-4334-9276-67c06d0fba6f/platforms/ios/www/verifica_usuario.php

I don't know why this error appears, the verifica_usuario.php is in the same folder as html,  I put bellow the form code of my login page:

 <form action="verifica_usuario.php" method="POST" id="formLogin">
            
            <label>User</label><br/>
            <input name="user" type="text" id="user" /><br/>
            <label>Password</label><br/>
            <input name="password" type="password" id="password" /><br/><br/>
            
            <input type="submit" name="Submit" value="LOGIN" /> 

</form>

 

Here are the verifica_usuario.php code:

<?php

session_start(); //inicia a sessao

include "http://localhost:8080/ConexaoBD/conecta.class";

$user = $_GET['user'];
$password = $_GET['password'];

if((!$user) || (!$password)){
    
    echo "Por favor, todos campos devem ser preenchidos! <br /><br />";
    include "index.html";
    
}else{
    $password = md5($password);
    
    $sql = pg_query(
        "SELECT * FROM pessoa WHERE email_pessoa = '{$user}' AND senha_pessoa = '{$password}' AND status_pessoa='A' ";
    );
    
    $login_check = pg_num_rows($sql);
    
    if($login_check > 0){
        
        while($row = pg_fetch_array($sql)){
            foreach ($row as $key => $val){
                $$key = stripslashes( $val );
            }
            
            $_SESSION['id_pessoa'] = $id_pessoa;
            $_SESSION['nome_pessoa'] = $nome_pessoa;
            $_SESSION['tipo_pessoa'] = $tipo_pessoa;
            $_SESSION['email_pessoa'] = $email_pessoa;
            
           header("location: area_restrita.php");
                
        }
    }else{
        echo "Você não pode logar-se! Este usuário e/ou senha não são válidos!<br />
             Por favor tente novamente!<br />";
        
        include "index.html";
    }
    
}


?>

 

Someone can help me please? Thanks!

**Sorry for my bad English :l

 

0 Kudos
3 Replies
Dwight_B_1
Beginner
7,359 Views

 

Might it be that you need an absolute url instead of a relative url here?
 action="verifica_usuario.php" 

RELATIVE -name of a file that is on the same machine as the one calling it. It usually is just a file name. 
ABSOLUTE -access a file on a remote machine.  it includes the protocol, path, and file name.

https://en.wikipedia.org/wiki/Absolute%20url

Maybe something like this?
 action="https://mysite.com/mobile-services/verifica_usuario.php" 

Hope this helps.
0 Kudos
Gabriel_A_
Beginner
7,358 Views

Dwight B. wrote:

 

Might it be that you need an absolute url instead of a relative url here?
 action="verifica_usuario.php" 

RELATIVE -name of a file that is on the same machine as the one calling it. It usually is just a file name. 
ABSOLUTE -access a file on a remote machine.  it includes the protocol, path, and file name.

https://en.wikipedia.org/wiki/Absolute%20url

Maybe something like this?
 action="https://mysite.com/mobile-services/verifica_usuario.php

Hope this helps.

Thanks for the reply, I put the verifica_usuario.php on server, and I changed the action url, and that error don't show anymore, but i have a new problem :(

At verifica_usuario.php have this lines:

include "index.html"; // line 13 and 43
header("location: area_restrita.php"); // line 36

index.html is the main page of my app and it's in the folder in my pc, don't in the server, so he can't find.

How can I solve it?

 

<?php

session_start(); //inicia a sessao

include "http://localhost:8080/ConexaoBD/conecta.class";

$user = $_GET['user'];
$password = $_GET['password'];

if((!$user) || (!$password)){
    
    echo "Por favor, todos campos devem ser preenchidos! <br /><br />";
    include "index.html"; //----------HERE------------
    
}else{
    $password = md5($password);
    
    $sql = pg_query(
        "SELECT * FROM pessoa WHERE email_pessoa = '{$user}' AND senha_pessoa = '{$password}' AND status_pessoa='A' ";
    );
    
    $login_check = pg_num_rows($sql);
    
    if($login_check > 0){
        
        while($row = pg_fetch_array($sql)){
            foreach ($row as $key => $val){
                $$key = stripslashes( $val );
            }
            
            $_SESSION['id_pessoa'] = $id_pessoa;
            $_SESSION['nome_pessoa'] = $nome_pessoa;
            $_SESSION['tipo_pessoa'] = $tipo_pessoa;
            $_SESSION['email_pessoa'] = $email_pessoa;
            
           header("location: area_restrita.php");
                
        }
    }else{
        echo "Você não pode logar-se! Este usuário e/ou senha não são válidos!<br />
             Por favor tente novamente!<br />";
        
        include "index.html";//------------HERE----------
    }
    
}


?>

 

0 Kudos
Diego_Calp
Valued Contributor I
7,358 Views

Hi Gabriel,

Is not clear to me if you are developing a device app or a web app. My answer is based in index.html as the main file created by XDK.

In first case, you should call the php authorization script from the app and process the result in the app. Not include index.html on the server side php scripts.

If it is the second case, you should build the app as a Web App, upload all files to server and add the php files (or call them with the complete url path)

I hope this help

Regards

Diego

0 Kudos
Reply