Jump to content

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.