Ok this is basicly what i need i know how to pass the usename and password to a url like so
HTTP://mysite.com/login.php?username=username&password=password
and yes before someone complains this is not secure its a game site and its just used for keeping scores and im the only one who can see the url its nothing valuable anyway just game scores.
i know you have to use the get command something like this
<form action="logon.php" method=get">
<input name="username">
<input name="password">
<input type=submit value="Login">
</form>
here is my code for the login page:
// Initialize the session
session_start();
// Check if the user is already logged in, if yes then redirect him to welcome page
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
header("location: welcome.php");
exit;
}
// Include config file
require_once "config.php";
// Define variables and initialize with empty values
$username = $password = "";
$username_err = $password_err = $login_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Check if username is empty
if(empty(trim($_POST["username"]))){
$username_err = "Please enter username.";
} else{
$username = trim($_POST["username"]);
// Check if password is empty
if(empty(trim($_POST["password"]))){
$password_err = "Please enter your password.";
$password = trim($_POST["password"]);
// Validate credentials
if(empty($username_err) && empty($password_err)){
// Prepare a select statement
$sql = "SELECT id, username, password FROM users WHERE username = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters
$param_username = $username;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Store result
mysqli_stmt_store_result($stmt);
// Check if username exists, if yes then verify password
if(mysqli_stmt_num_rows($stmt) == 1){
// Bind result variables
mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password);
if(mysqli_stmt_fetch($stmt)){
if(password_verify($password, $hashed_password)){
// Password is correct, so start a new session
// Store data in session variables
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
// Redirect user to welcome page
// Password is not valid, display a generic error message
$login_err = "Invalid username or password.";
// Username doesn't exist, display a generic error message
echo "Oops! Something went wrong. Please try again later.";
// Close statement
mysqli_stmt_close($stmt);
// Close connection
mysqli_close($link);
?>
Login
body{ font: 14px sans-serif; }
.wrapper{ width: 360px; padding: 20px; }
Please fill in your credentials to login.
if(!empty($login_err)){
echo '
';
" method="post">
Username
Password
Don't have an account? Sign up now.
Hi @Jasper Steller
I would like to know where you are calling above code?
This code seems to be in php so would like to know how and where you are integrating with Outsystems?
Hi @Jasper Steller ,
Your question doesn't seem to involve any OutSystems-related issue. Just keep in mind that you should probably try to ask that question in a PHP group or forum as they might get you more answers and options.
But to answer your question, it's really just using $_GET instead of $_POST. They are actually not command or function. Both of them are generally arrays that comes from what you have passed, via form values or url parameters. When your page loads, you will basically have values in your $_GET and $_POST arrays and you just have to access what you need via keys (key-value pair).
The parameters key-value pair will be loaded into your $_GET, and the form values will get loaded into the $_POST.
if(empty(trim($_GET["username"]))){
$username = trim($_GET ["username"]);
if(empty(trim($_GET["password"]))){
$password = trim($_GET ["password"]);
Regards,Bryan