Hi,

I am developing a PHP module where I need to pass a particular data through different pages without notifying the user about it. The site I am building have forms on every page except 1. So what I was doing before was sending that data through forms in a hidden format. But now I am in a fix. The reason is that in the last page of the site there in no form but there are links to revisit the previous pages. So when a user click on those links that information vanishes. So how could I restore that value. I tried using sessions but failed miserably. I am new to PHP and have problems maintaining sessions. So please suggest me a method without the use of sessions and forms

Thanks in advance

Gaurav

Dani AI

Generated

The thread shows the common quick suggestions: pointed at putting data in the link, mentioned hidden fields, and mentioned sessions. For a solution that avoids forms and (per the OP) sessions, two reliable patterns work well in practice: client-side storage and a server-side token lookup.

Cookies (server-readable automatically)
Set a small identifying value or preference in a cookie on the final page, then read it on any revisited page. Cookies are sent with each request so the server sees them without forms or extra URL parameters. Set secure flags and an expiration. Example PHP pattern:

<?php
// set before any output
setcookie('my_token', $token, time()+1800, '/', '', true, true);
$val = $_COOKIE['my_token'] ?? null;
?>

See the PHP setcookie docs for details: PHP setcookie manual.

Browser storage (client-only, fast)
Use localStorage or sessionStorage from JavaScript if the value only needs to live on the client (e.g., UI state, non-sensitive flags). This is not sent to the server automatically, but it survives link navigation and back/forward:

<script>
localStorage.setItem('mydata','somevalue');
var v = localStorage.getItem('mydata');
</script>

MDN has the storage reference: Window.localStorage.

Token + server-store (best for security)
For anything sensitive, store the real data server-side (database or cache) and place only a short random token in a cookie or localStorage. On each request the server looks up the token and retrieves the data. This avoids exposing values in the browser and lets you add expiry and revocation.

Security notes: never store secrets or PII in plain client storage; always use HTTPS; set Secure and HttpOnly for cookies when appropriate; validate tokens and expire them server-side. For cookie security guidance see OWASP: Secure Cookie Attribute.

Recommended Answers

All 3 Replies

why acnu use sessions

by adding ?hiddenname=hiddenvalue[&hiddenname2=hiddenvalue2] end of url address

By adding this:

<input type="hidden" name="hiddenname">

use this where ever you want to send by hidden....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.