-4

First of all I am a new student of learning php. Currently I am writing a piece of code, But getting this error when i compile it.

Notice: Undefined index: ref in D:\xampp\htdocs\uploadthis\includes\config.inc.php on line 8

my file config.inc.php

<?php
require_once ('database/database.inc.php');
$myDb = new Db;
include ('siteconfig.inc.php');
require_once ('controls.inc.php');
if(isset($_COOKIE["usReferrer"])){
}else{
setcookie("usReferrer",limpiar($_GET["ref"]),time()+7776000);
}
?>

I hope you Guys can tell me how can i get off from this error.

1 Answers1

0

Seems like you are not sending the parameter ref on your URL.

Make sure your URL looks like this ,

http://www.yourpage.com/somepage.php?ref=test
                           ---------^

Always use an isset construct to check whether the variable exists.

if(isset($_GET['ref']))
{
echo "Set";
}
else
{
echo "Not Set';
}

EDIT :

I have used cookies. So in fine what my codes will be look like?

This is how you should do.

<?php
require_once ('database/database.inc.php');
$myDb = new Db;
include ('siteconfig.inc.php');
require_once ('controls.inc.php');

if(isset($_GET['ref']))
{
if(isset($_COOKIE["usReferrer"])){
}else{
setcookie("usReferrer",limpiar($_GET["ref"]),time()+7776000);
}
}

?>
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126