Fake Tweet Generator Tool Script Using css html php java

 Fake Tweet Generator Tool Script Using css html php java

Creating a fake tweet generator tool can be a fun project. Here's a basic example of a fake tweet generator using HTML, CSS, PHP, and JavaScript:

Fake Tweet Generator Tool Script Using css html php java


index.html:


<!DOCTYPE html>
<html>
<head>
    <title>Fake Tweet Generator</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <h1>Fake Tweet Generator</h1>
    <form action="generate_tweet.php" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>
        <br>
        <label for="tweet">Tweet:</label>
        <textarea id="tweet" name="tweet" required></textarea>
        <br>
        <button type="submit">Generate</button>
    </form>
    
    <div id="result">
        <?php
        if (isset($_GET['tweet'])) {
            echo '<div class="tweet">';
            echo '<span class="username">' . $_GET['username'] . '</span>';
            echo '<span class="tweet-content">' . $_GET['tweet'] . '</span>';
            echo '</div>';
        }
        ?>
    </div>
</body>
</html>


style.css:


body {
    text-align: center;
    margin-top: 100px;
    font-family: Arial, sans-serif;
}

h1 {
    color: #333;
}

form {
    margin-top: 20px;
}

label {
    display: block;
    margin-bottom: 5px;
}

input[type="text"], textarea {
    width: 300px;
    padding: 5px;
}

button {
    padding: 10px 20px;
    font-size: 16px;
}

.tweet {
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    padding: 10px;
    margin-top: 20px;
}

.username {
    font-weight: bold;
}

.tweet-content {
    margin-top: 10px;
}


generate_tweet.php:


<?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = $_POST['username']; $tweet = $_POST['tweet']; // Escape HTML characters to prevent XSS attacks $username = htmlspecialchars($username, ENT_QUOTES, 'UTF-8'); $tweet = htmlspecialchars($tweet, ENT_QUOTES, 'UTF-8'); // Redirect to index.html with query parameters header('Location: index.html?username=' . urlencode($username) . '&tweet=' . urlencode($tweet)); exit(); } ?>


In this example, the user is asked to enter a username and a tweet message in the HTML form. When the form is submitted, the data is sent to the generate_tweet.php file using the POST method. The PHP script then escapes HTML characters to prevent cross-site scripting (XSS) attacks, and redirects back to the index.html page with the username and tweet as query parameters in the URL.

The index.html file checks if the tweet parameters are present in the URL and displays the generated tweet in a styled format.

Save all these files in the same directory and ensure you have a server environment with PHP support to run the code.


Post a Comment

0 Comments