Jump to content

Problem with php sessions


flit

Recommended Posts

Hi there,

 

I have the following links on a page:

 

<a href="7.php<?php session_start(); $_SESSION['id']=1;?>">Test 1</a>

<br>

<a href="7.php<?php session_start(); $_SESSION['id']=2;?>">Test 2</a>

<br>

<a href="7.php<?php session_start(); $_SESSION['id']=3;?>">Test 3</a>

<br>

<a href="7.php<?php session_start(); $_SESSION['id']=8;?>">Test 8</a>

 

When I click the first link [test 1], the value 8 is written in the session file and not the value 1

When I click the second link I want the value 2 to be added into the session file. I want my

session file to look like this:

id|i:1,2;

 

Can somebody tell me what I am doing wrong??

Link to comment
https://forums.phpfreaks.com/topic/100916-problem-with-php-sessions/
Share on other sites

You only need to call session_start() only once . You don't call it everytime you want to use a session variable. You should call session_start() before any output. If you have any form of output you'll get either a blank page or an "header already sent" error message.

 

If you don't want PHP to continue the script at a certain pioint use die(); or exit;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.