-1

For example, i have 1 website.

Domain,com ( Index,php )

Domain,com/login,php ( login form )

Domain,com/home,php ( after login )

Script of Domain.com/login.php is like this

<form action="access,php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="button" value="submit"> </form>

In domain*com/home.php just display like this

Hello world

I want to curl Hello world, but I need to login first before I can access home.php and curl the page

Community
  • 1
  • 1
  • Did you already write something on your own? – rrr Dec 03 '17 at 11:04
  • Typing "php curl login" would have gotten you to the duplicate in no time. Please go read [ask], and make an actual effort next time. – CBroe Dec 03 '17 at 11:28

1 Answers1

1

If you login you have to save the data of the user in a SESSION. Look at this loginscript (your login.php):

        <?php
        session_start(); //start the SESSION to save the values
        if(isset($_SESSION['username'])) { //If user already is logedin
        header("Location: home.php");
        }



        if(isset($_GET['username'])) { //your submitted form
        $username = $_GET['username'];
        $passwort = $_GET['passwort'];

        $pdo = new PDO('mysql:host=yourhost;dbname=databasename', 'username', 'password');

        $statement = $pdo->prepare("SELECT * FROM users WHERE username = :username");
        $result = $statement->execute(array('username' => $username));
         $user = $statement->fetch();

         //Check Password
        if ($user !== false && password_verify($passwort, $user['passwort'])) {
         $_SESSION['username'] = $user['username'];

        header("Location: home.php"); //Go to home.php
        }
        }
        ?>
        <html>
        Your Code
        </html>

Now you are directed to your home.php. Just check there if the SESSION has the right value:

<?php
session_start();
if(!isset($_SESSION['username'])) { //If user isnt logedin
header("Location: login.php"); //return to login. You can also change the command to what you like to do it
}
?>
<html>
Your Code
</html>
Sentry
  • 125
  • 1
  • 10