Jump to content

sessions inside functions?


spires

Recommended Posts

Hi Guys.

 

I'm trying to create a session inside a function.

At the top of every page I have <?PHP tracking(); ?>

which calls in the function.

 

What should happen is on the first page that the user

comes to (From Adwords) will place the keyword in to

a session (page?kw=keyword). Then if the $_GET[kw] is not

present, it will display the session.

 

How ever, it's not working. Below is the code i'm trying to

get to work. Please could you advice what I need to do.

 

Thanks

 

This is the function.

<?PHP
function tracking(){
session_start();

$get_Keyword = $_GET['kw'];

if (get_Keyword){
$_SESSION['key'] = $get_Keyword;
echo $_SESSION['key'];
}else{
echo $_SESSION['key'];
}

}
?>

Link to comment
Share on other sites

you are missing a $ in front of your variable in your IF statement, here is a slightly cleaner version of the code too

 

<?php
function tracking(){
  session_start();
  if ($_GET['kw'])
    $_SESSION['key'] = $_GET['kw'];
  echo $_SESSION['key'];
}
?>

Link to comment
Share on other sites

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.