PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

PHP · Theory

Sessions

← All stacks

Theory

44/352

Sessions

A session remembers the user across pages. session_start(); then $_SESSION['user'] = 'Asha'; Next page: session_start(); echo $_SESSION['user']; PHP stores data on the server and sends a cookie with the session id.

session_start() must run before any HTML output. session_destroy() on logout. Don’t store passwords in $_SESSION.

Trap — forgetting session_start(). Trap: session_start after echo.

Exam tip

session_start(); $_SESSION['user']='Asha';

Example

<?php
// Sessions
$scores = [80, 90, 70];
$avg = array_sum($scores) / count($scores);
echo "avg=" . number_format($avg, 1) . "\n";
foreach ($scores as $s) {
  if ($s >= 80) echo "high: $s\n";
}

Sessions: scores array, print avg, then high marks. Say the output.

Short notes

  • Def$_SESSION is server-side login memory.
  • Rulesession_start() first. Cookie holds the id.
  • TrapHTML before session_start.

Questions

1

Where is session data stored?

44 / 352

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.