Lemmy.InButts.LOL
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
amargo85@infosec.pub to PHP@programming.devEnglish · 1 year ago

How do I create dynamic websites using PHP/javascript/HTML/CSS?

chat-to.dev

external-link
message-square
1
link
fedilink
-3
external-link

How do I create dynamic websites using PHP/javascript/HTML/CSS?

chat-to.dev

amargo85@infosec.pub to PHP@programming.devEnglish · 1 year ago
message-square
1
link
fedilink
#
Overview Dynamic websites are the website on which a user sends the request from the client side to the server side and the data is rendered in the backend, as PHP is a server side scripting language so it plays the main role while creating dynamic websites. Some of the dynamic websites are like website admin panels or the searched content for the specific users. So the HTML, CSS and JavaScript are used on the client side of the website to create a user frontend and the PHP is used as a backend scripting language to render and retrieve the user data and send back to the user in the frontend. # ALGORITHM > + Download and install the XAMPP server from the official website. + Now start the apache server to run the website on our local computer. + Now open the “htdocs” folder in the XAMPP folder of your directory. + Now create a folder as “dynamicWeb”. + Now create a main “index.php” file to start building the website. + Now add the HTML boilerplate to the “index.php” file. + Now add the HTML form to the page with the method and action attribute with their specific value as “POST” and “data.php” respectively. The “data.php” is the backend file in which the php script is written. + Now add two input fields to the form as name and technology with the submit button. + Now create a “data.php” file in the same folder. Use the open and closing php tag to use the php. ```bash ``` > + Now create if syntax to check whether the server request is POST or GET. ```php if($_SERVER["REQUEST_METHOD"]=="POST"){} ``` > + Now create a variable as name which will store the name from the client side. ```php $name = $_POST['name']; $tech = strtolower($_POST['tech']); ``` > + If the request is POST then create a class with the name as “MyTech” and also create a public variable “username”. ```php class MyTech{ public $username; } ``` > + Now create three functions as frontend(), backend() and database() with the parameter “name” passed to the function. ```php public function frontend($uname){ echo "Hello ". $uname .', your FrontEnd Content is here. '. "
  • HTML
  • CSS
  • Bootstrap
  • JavaScript
  • ReactJs
  • "; } public function backend($uname){ echo "Hello ". $uname .', your BackEnd Content is here.'."
  • NodeJs
  • ExpressJs
  • Middlewares
  • Http Methods
  • "; } public function database($uname){ echo "Hello ". $uname .', your Database Content is here.'."
  • MySql
  • MongoDB
  • DynamoDB
  • Casandra
  • PostgreSql
  • "; } ``` > + Now create another if-else function to it which checks for the following entry through the frontend. ```php if ($tech == "frontend" || $tech == "backend" || $tech == "database") {} ``` > + If the condition satisfies then create the object of the class else print the alert. ```php $myObj= new MyTech(); $myObj->$tech($username=$name); else{ echo "Hello ". $name .", ". $tech ." will be uploaded shortly."; } ``` > + Now create a HTML button to the page with the function “history.back()” outside the php closing tag ```html ◀ Back ``` > + The dynamic website with php is ready. + Now open the browser and type “localhost/dynamicWeb” in the address bar http://localhost/dynamicWeb/ > + The website will be opened with its functionality. ## Example Here’s an example by which you can learn to create a dynamic website using HTML, CSS, JavaScript and PHP. In which the frontend part is created using HTML, CSS and the server side scripting is done using PHP. In this example we have created a feature in which there is a form in which a user enters his name and the technology name of which he wants to retrieve the information with a button. When the user triggers the button the information from the frontend is sent to the server is the data is rendered and sent back to the user. ```html index.php Dynamic Web
    tutorialspoint.com
    Available Technologies
  • Frontend
  • Backend
  • Database
  • Get Content
    ``` data.php ```php HTML
  • CSS
  • Bootstrap
  • JavaScript
  • ReactJs
  • "; } public function backend($uname){ echo "Hello ". $uname .', your BackEnd Content is here.'."
  • NodeJs
  • ExpressJs
  • Middlewares
  • Http Methods
  • "; } public function database($uname){ echo "Hello ". $uname .', your Database Content is here.'."
  • MySql
  • MongoDB
  • DynamoDB
  • Casandra
  • PostgreSql
  • "; } } if ($tech == "frontend" || $tech == "backend" || $tech == "database") { $myObj= new MyTech(); $myObj->$tech($username=$name); }else{ echo "Hello ". $name .", ". $tech ." will be uploaded shortly."; } } ?> ◀ Back ``` # CONCLUSION PHP is a good server side scripting language which helps the developer to embed the HTML code with it. To make the PHP project more scalable we can also use the PHP frameworks such as Laravel, symphony cakephp, so these are the most popular frameworks. In the above example we have used the concept of class and objects to get the user data, but we can also use the MySql database which makes it more helpful to make a dynamic website. So when a user sends the request to the server, the server retrieves the data from the database and sends to the user only specific information which the user has requested for.
    • shnizmuffinA
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      Yes.

    PHP@programming.dev

    php@programming.dev

    Subscribe from Remote Instance

    Create a post
    You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !php@programming.dev

    Welcome to /c/php! This is a community for PHP developers and enthusiasts to share and discuss anything related to PHP. From the latest updates and tutorials, to your burning questions and amazing personal projects, we welcome all contributions.

    Let’s foster an environment of respect, learning, and mutual growth. Whether you’re an experienced PHP developer, a beginner, or just interested in learning more about PHP, we’re glad to have you here!

    Let’s code, learn, and grow together!

    Visibility: Public
    globe

    This community can be federated to other instances and be posted/commented in by their users.

    • 3 users / day
    • 1 user / week
    • 8 users / month
    • 64 users / 6 months
    • 1 local subscriber
    • 684 subscribers
    • 89 Posts
    • 129 Comments
    • Modlog
    • mods:
    • Ategon@programming.dev
    • mbd@programming.dev
    • BE: 0.19.12
    • Modlog
    • Legal
    • Instances
    • Docs
    • Code
    • join-lemmy.org