Home > database >  how to send data from a php file to another php file?
how to send data from a php file to another php file?

Time:09-03

i am making a "login and signup form" actions for my file. i searched about this many times but i cant find the answer and most of the topics are about sql which i don't use for these files. im looking for a answer without include, sql, or session in my files here's my codes

html:

<!doctype html>

<html>
    <head>
        <meta charset="utf-8">

        <title>Gleacc</title>

        <!-- Load external CSS styles -->
        <link rel="stylesheet" href="styles.css">
        
    </head>

    <body>

        <h1>Gleacc GG</h1>
        <br>
        <form action="data/signedup.php" method="get">
            <label for="usn">
                <input placeholder="Username" name="usn" required>
            </label>
            <br>
            <label for="psw">
                <input placeholder="Password" name="psw" required>
            </label>
            <br>
            <input type="submit" value="Submit">
        </form>

        <!-- Load external JavaScript -->
        <script src="scripts.js"></script>
        
    </body>

</html>

signuped. php:

<?php 
$psw = $_GET['psw'];
$usn = $_GET['usn'];
echo "<form action="data/logined.php" method="post"><input placeholder="Username" name="usn" required><br><input placeholder="Password" name="psw" required><br><input type="submit" value="Submit"></form>";
?>

logined.php: none since we cant compair the input because we cant get the $usn and $psw from signuped.php

CodePudding user response:

I think you are being silly.

  1. Are the users signing up every time they are on the website? If not, then you need to save their username and password in some sort of database.
  2. Any other method used in signuped is exposing data that you shouldn't be exposing.

Here is one way to do what you want and make it a tad secure.

<?php 
$psw = encrypt($_POST['psw']);
$usn = encrypt($_POST['usn']);

echo "<form action='data/logined.php' method='post'>
<input placeholder='Username' name='usn' required><br>
<input placeholder='Password' name='psw' required><br>
<input class='hidden' value='$usn' name='encusn'><br>
<input class='hidden' value='$psw' name='encpsw'><br>
<input type='submit' value='Submit'></form>";
?>

Where you use CSS to hide the two inputs. Be warned that it is not hard to expose them in the browser by anyone with even a little knowledge of CSS.

In your logined file you encrypt the entered values and compare them with encrypted values from the hidden inputs. I wouldn't use a two-way algorithm and try to decrypt the encrypted values.

CodePudding user response:

first make sure that signuped.php is placed inside the folder data which placed same level as the html file. then change the action in the html file from get to post and try var_dump($_POST) to see if the inputs has been submited.

  •  Tags:  
  • php
  • Related