Lazar Lazar - 2 months ago 12
HTML Question

Php session in two php files

if(empty($prvi)&& empty($drugi)&&empty($treci)&&empty($cetvrti)){
$upit1 = "INSERT INTO korisnici (ime, prezime, email, sifra, psifra, zanimanje, brojracuna, mesec, godina, banka) VALUES ('$ime','$prezime','$email','$sifra','$psifra','$zanimanje','$kartica','$mesec','$godina','$banka')";
$rez = mysqli_query($conn, $upit1);

$_SESSION['id'] = $email;


this is first.php

in secound.php i want to echo session['id']

In
first.php
I have
session_start();
and
$_SESSION['id'] = $email;


$email
is input tag.

How can I echo session in
secound.php
? I have
session_start();
too.

first.php
and
secound.php
are in the same folder.

Answer

if you have session_start(); on the first and you store the $_SESSION you just need to open session like you said and do something like

session_start();
$test = $_SESSION['id'];
echo $test;

if it doesn't work show some code.

Example First Page:

$email = $_POST['email'];
//some mysql inserts ? 
if (sql worked) {
  session_start();
  $_SESSION['id'] = $email;
  header("Location:secound.php");
}

Second

session_start();
$store = $_SESSION['id'];
echo $store;