Hello all. I am trying to set a session variable as a string like this.

$_SESSION['something']="hello";

this does not work

I also tried this. but it didn't work;

$name =$_SESSION['something']."hello";

and if i do this

$_SESSION['something']=$_SESSION['something']."hello";

the value ends up like this hellohellohellohellohello


So what im trying to do is set a session string , but i cant find the correct way of doing it even after lots of research. Does anyone know the solution thanks!

<?php

   session_start(); // this initializes the session, and, should be on each of your main pages that you use        
                           //    sessions.
   $_SESSION['string'] = "Hello, this is a string";

  echo $_SESSION['string']; // this outputs Hello, this is a string.
?>

- Hope this helps :)

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.