0% found this document useful (0 votes)
6 views13 pages

$ Request Vs $ Server

The document explains the use of PHP superglobal arrays $_REQUEST and $_SERVER, detailing their purposes and examples of usage. It also covers sorting functions asort() and ksort() for associative arrays, and outlines characteristics of effective web navigation along with various types of navigation systems. Additionally, it provides a step-by-step guide to creating an HTML form, storing data in a MySQL database using PHP, and displaying the data securely with prepared statements.

Uploaded by

cavife3393
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views13 pages

$ Request Vs $ Server

The document explains the use of PHP superglobal arrays $_REQUEST and $_SERVER, detailing their purposes and examples of usage. It also covers sorting functions asort() and ksort() for associative arrays, and outlines characteristics of effective web navigation along with various types of navigation systems. Additionally, it provides a step-by-step guide to creating an HTML form, storing data in a MySQL database using PHP, and displaying the data securely with prepared statements.

Uploaded by

cavife3393
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

$_REQUEST vs $_SERVER

$resquest and $server use in php

Sure! In PHP, $_REQUEST and $_SERVER are superglobal arrays that help you access different types of data.

1. $_REQUEST

It is an associative array that contains data sent to the script via GET, POST, and COOKIE methods.

It’s like a combined array of $_GET, $_POST, and $_COOKIE.

Useful when you want to accept input without worrying about the method used to send it.

Example:

php

// Suppose a form submits a field named 'username'

echo $_REQUEST['username'];

If the form used GET or POST or if there’s a cookie named 'username', this will access it.

2. $_SERVER

It’s an array containing information about headers, paths, and script locations.

Provides data about the server and execution environment.


Useful for getting info like the current script name, server IP, user agent, request method, etc.

Common $_SERVER variables:

$_SERVER['PHP_SELF'] — The filename of the currently executing script

$_SERVER['REQUEST_METHOD'] — The request method used (GET, POST, etc.)


$_SERVER['HTTP_USER_AGENT'] — Information about the user's browser

$_SERVER['SERVER_NAME'] — The server host name


$_SERVER['REMOTE_ADDR'] — The IP address of the client

Example:

php

echo "Request method: " . $_SERVER['REQUEST_METHOD']; // Outputs: GET or POST


echo "Current script: " . $_SERVER['PHP_SELF']; // Outputs the path of the script

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/13
Summary

Superglobal Contains Example Use

$_REQUEST Data sent via GET, POST, or COOKIE Retrieve form input without method-specific code

$_SERVER Server and execution environment info Get request method, script name, client IP, etc.

If you want, I can also show you small practical examples for both! Would you like that?

asort and ksort function in php

Sure! Here's a quick explanation of asort() and ksort() functions in PHP:

1. asort()

Sorts an associative array by values in ascending order.

Maintains the key-value association (keys stay linked to their values).

Useful when you want to sort the array by the values but keep the original keys intact.

Syntax:

php

asort(array &$array, int $flags = SORT_REGULAR): bool

Example:

php

$fruits = [
"d" => "lemon",
"a" => "orange",
"b" => "banana",
"c" => "apple"
];

asort($fruits);

print_r($fruits);

Output:

php

Array
(
[c] => apple
[b] => banana
[d] => lemon

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/13
[a] => orange
)

2. ksort()

Sorts an associative array by keys in ascending order.


Maintains the key-value relationship.

Useful when you want the array sorted based on the keys.

Syntax:

php

ksort(array &$array, int $flags = SORT_REGULAR): bool

Example:

php

$fruits = [
"d" => "lemon",
"a" => "orange",
"b" => "banana",
"c" => "apple"
];

ksort($fruits);

print_r($fruits);

Output:

php

Array
(
[a] => orange
[b] => banana
[c] => apple
[d] => lemon
)

Summary

Function Sorts by Keeps key association? Sort order


asort() Values Yes Ascending
ksort() Keys Yes Ascending

If you want, I can also show you arsort() and krsort() for descending order! Want me to?

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/13
Explain navigation and characteristics of effective navigation.

✅ Navigation in Web Design


Navigation refers to the system that allows users to move around a website, access content, and
understand its structure. It's typically made up of menus, links, and buttons that guide users to various
sections and pages.

🔹 Types of Website Navigation


1. Main/Primary Navigation – The top-level menu (e.g., Home, About, Services, Contact)

2. Secondary Navigation – Submenus or dropdowns for related pages.


3. Footer Navigation – Repeated or less critical links at the bottom.
4. Sidebar Navigation – Vertical menus usually on the left/right of the page.

5. Breadcrumb Navigation – Shows the user's path (e.g., Home > Products > Laptops)
6. Hamburger Menu – Collapsible menu (especially in mobile design).

🌟 Characteristics of Effective Navigation


1. Clarity

Labels and links must be easily understandable.

Avoid technical jargon or confusing terms.


Example: Use "Contact Us" instead of "Reach Interface".

2. Consistency

Navigation structure should be the same across all pages.

Menus, positions, and styles should not change unexpectedly.

3. Simplicity

Keep the number of menu items minimal and well-organized.


Avoid overwhelming users with too many choices.

4. Responsiveness

Navigation should work well on all devices: desktop, tablet, mobile.


Use collapsible/hamburger menus for mobile.

5. Visibility

Navigation elements should be easy to find (usually top or side).

Highlight the current page or active section clearly.

6. Accessibility

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/13
Use proper HTML elements (<nav>, <ul>, <a>) for screen readers.

Include keyboard navigation and focus styles.


7. Logical Hierarchy

Group related links together.


Use categories and subcategories meaningfully.

8. Feedback

Highlight the active menu item.

Provide visual feedback on hover or click.

9. Fast Load Time

Navigation should not depend heavily on large scripts or animations.


Keep it lightweight for quick access.

10. Search Integration (Optional)

A search bar helps users quickly find what they're looking for if navigation doesn't cover
everything.

🧭 Example of a Simple Navigation Bar (HTML)


html

<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>

Would you like a real web page example with responsive navigation?

explain all types

Sure! Here's a detailed explanation of all common types of website navigation with examples:

🧭 Types of Website Navigation


1. Horizontal Navigation Bar (Top Navigation)

Placed at the top of the website, usually in a row.

Most common type.

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 5/13
Includes links like: Home, About, Services, Contact, etc.

✅ Example:
html

<nav>
<ul style="display: flex; gap: 20px;">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>

✔️ Best For:
Simple websites
Quick access to top-level pages

2. Vertical Navigation Bar (Sidebar Navigation)

Placed on the left or right side of the page.


Often used in admin panels or dashboards.

✅ Example:
html

<nav>
<ul>
<li><a href="#">Dashboard</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Logout</a></li>
</ul>
</nav>

✔️ Best For:
Web apps
Control panels

Complex interfaces

3. Dropdown Navigation

Menu items expand to show submenus when hovered or clicked.

Good for organizing sub-categories.

✅ Example (HTML only):


Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/13
html

<ul>
<li>
<a href="#">Services</a>
<ul>
<li><a href="#">Web Design</a></li>
<li><a href="#">SEO</a></li>
</ul>
</li>
</ul>

✔️ Best For:
Websites with categories and subcategories

E-commerce or agency websites

4. Hamburger Menu (Mobile Navigation)

Three stacked lines icon used on mobile.

Expands when clicked to show menu.

✅ Example (Concept):
html

<!-- Button shows hamburger icon -->


<button id="menuBtn">☰</button>

<!-- Hidden menu -->


<ul id="mobileMenu" style="display:none;">
<li><a href="#">Home</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>

✔️ Best For:
Responsive design

Mobile-first websites

5. Footer Navigation

Navigation links placed at the bottom of the website.

Usually includes secondary links like Privacy Policy, Terms, etc.

✅ Example:
html

<footer>
<ul>
<li><a href="#">Privacy Policy</a></li>

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 7/13
<li><a href="#">Terms of Service</a></li>
<li><a href="#">Help</a></li>
</ul>
</footer>

✔️ Best For:
Legal or less important links

SEO-friendly bottom-of-page structure

6. Breadcrumb Navigation

Shows the path user has followed inside a site.


Example: Home > Products > Laptops > Dell

✅ Example:
html

<nav>
<a href="#">Home</a> &gt;
<a href="#">Products</a> &gt;
<a href="#">Laptops</a>
</nav>

✔️ Best For:
E-commerce websites
Deep hierarchical sites

7. Tabbed Navigation

Looks like browser tabs; clicking a tab shows related content.


Usually used within a section (not entire site navigation).

✅ Example:
html

<ul class="tabs">
<li><a href="#tab1">Overview</a></li>
<li><a href="#tab2">Specs</a></li>
<li><a href="#tab3">Reviews</a></li>
</ul>

✔️ Best For:
Product pages

User profile panels

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 8/13
8. Mega Menu Navigation

A large dropdown menu showing all categories and subcategories at once.

Can include text, links, images, and icons.

✔️ Best For:
E-commerce or news websites

Sites with many menu options

9. Sticky or Fixed Navigation

Menu stays visible at the top even when scrolling.

✔️ Best For:
Long scroll websites

Blogs or single-page apps

📝 Summary Table
Type Position Best Use Case

Horizontal Nav Top Simple websites, standard layout


Vertical Nav Left/Right Admin panels, web apps

Dropdown Nav Top/Sub-level Subcategories, large menus

Hamburger Menu Top (Mobile) Responsive/mobile-first design


Footer Nav Bottom Legal info, extra links

Breadcrumb Top (below nav) Show path/depth in site hierarchy


Tabbed Nav Section level Product tabs, dashboards

Mega Menu Top/Dropdown E-commerce, news, corporate sites

Sticky Nav Top (fixed) One-page or scroll-heavy websites

Would you like a real HTML demo combining some of these types?

give simple exmaple code to fetch data of html form display it through php after storing it in
database

Sure! Here's a simple working example of how to:

1. Create an HTML form to collect user data

2. Store the data in a MySQL database using PHP


3. Fetch and display the data on the same or another page

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 9/13
📌 Step-by-step Guide
✅ 1. Database Setup (MySQL)
sql

CREATE DATABASE mydb;

USE mydb;

CREATE TABLE users (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);

✅ 2. HTML Form ( form.html)

html

<!DOCTYPE html>
<html>
<head>
<title>Simple Form</title>
</head>
<body>
<h2>User Form</h2>
<form action="submit.php" method="POST">
Name: <input type="text" name="name" required><br><br>
Email: <input type="email" name="email" required><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

✅ 3. PHP Script to Store & Display Data ( submit.php)

php

<?php
// 1. Database connection
$conn = new mysqli("localhost", "root", "", "mydb");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// 2. Get data from form


$name = $_POST['name'];
$email = $_POST['email'];

// 3. Insert data into database


$sql = "INSERT INTO users (name, email) VALUES ('$name', '$email')";
if ($conn->query($sql) === TRUE) {
echo "<h3>Data inserted successfully!</h3>";
} else {
echo "Error: " . $conn->error;
}

// 4. Display all users


echo "<h2>All Users:</h2>";
$result = $conn->query("SELECT * FROM users");

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/13
if ($result->num_rows > 0) {
echo "<table border='1' cellpadding='5'><tr><th>ID</th><th>Name</th><th>Email</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>". $row["id"] ."</td><td>". $row["name"] ."</td><td>". $row["email"] ."</td></
}
echo "</table>";
} else {
echo "No data found.";
}

$conn->close();
?>

📌 Notes:
Make sure your MySQL server is running.

Change "localhost", "root", "", "mydb" to match your DB credentials.


This is a basic example. For security:

Use prepared statements (to prevent SQL injection).

Sanitize user input.

Would you like a version with validation and prepared statements too?

example with prepared statement

Great! Here's an improved and secure example using prepared statements in PHP to prevent SQL
injection while storing and displaying HTML form data.

✅ 1. Database Setup (MySQL)


Run this SQL code in phpMyAdmin or MySQL terminal:

sql

CREATE DATABASE mydb;

USE mydb;

CREATE TABLE users (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL
);

✅ 2. HTML Form ( form.html)

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/13
html

<!DOCTYPE html>
<html>
<head>
<title>Secure User Form</title>
</head>
<body>
<h2>User Registration</h2>
<form action="submit.php" method="POST">
Name: <input type="text" name="name" required><br><br>
Email: <input type="email" name="email" required><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

✅ 3. PHP Script with Prepared Statement ( submit.php)

php

<?php
// 1. Connect to database
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydb";

$conn = new mysqli($servername, $username, $password, $dbname);

// 2. Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// 3. Get form data safely


$name = $_POST['name'];
$email = $_POST['email'];

// 4. Prepare SQL statement to insert data


$stmt = $conn->prepare("INSERT INTO users (name, email) VALUES (?, ?)");
$stmt->bind_param("ss", $name, $email);

// 5. Execute and confirm


if ($stmt->execute()) {
echo "<h3>Data inserted securely!</h3>";
} else {
echo "Error: " . $stmt->error;
}

$stmt->close();

// 6. Display all records


echo "<h2>All Users:</h2>";
$result = $conn->query("SELECT * FROM users");

if ($result->num_rows > 0) {
echo "<table border='1' cellpadding='5'><tr><th>ID</th><th>Name</th><th>Email</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>". $row["id"] ."</td><td>". $row["name"] ."</td><td>". $row["email"] ."</td></
}
echo "</table>";
} else {
echo "No users found.";
}

$conn->close();
?>

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 12/13
🔐 Benefits of Prepared Statements
Protects against SQL Injection

Automatically escapes user input


Safer for production environments

Would you like to add features like input validation, alerts, or redirect to another page after submission?

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 13/13

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy