session set in .php file for jumi - joomla

1.2k Views Asked by At

I run into a problem using session in .php file i attached in jumi

How do i set a session in in that page? when i use :

//this define and require I use from reading the other papers
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );

require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');

$mainframe = JFactory::getApplication('site');
$session = &JFactory::getSession();

if(isset($_GET['id'])){ 
    var_dump($id= $_GET['id[i]']);
} else {echo "No session ";}

// code connect to db
// render out the items
//
foreach($rows as $i=>$row){ 
    $id[$i] = $row['rid'];
    $name[$i] = $row['rname'];

    $view .= '<tr>
                  <td>'.$id[$i].'</td>
                  <td><a href="http://www.thispage.php?id='.$id[$i].'">'.$name[$i].'</a></td>';
?>
}
<p><?php echo $view.'</tr></table>'; ?> </p>

......

It doesn't let me find the sub-page of id=1 that I clicked . What is the better way to deal with this kind of thing? thank you.

2

There are 2 best solutions below

0
On BEST ANSWER

You have a syntax error try this before you go any further:

</php
//this define and require I use from reading the other papers
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );

require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');

$mainframe = JFactory::getApplication('site');
$session = &JFactory::getSession();

if(isset($_GET['id'])){ 
    var_dump($id= $_GET['id[i]']);
} else {
    echo "No session ";
}

// code connect to db
// render out the items
//
foreach($rows as $i=>$row){ 
    $id[$i] = $row['rid'];
    $name[$i] = $row['rname'];

    $view .= '<tr>
                  <td>'.$id[$i].'</td>
                  <td><a href="http://www.thispage.php?id='.$id[$i].'">'.$name[$i].'</a></td>';
}
?>
<p><?php echo $view.'</tr></table>'; ?></p>
0
On

Looking at the way Jumi includes PHP files, you should start with:

defined('_JEXEC') or die('Restricted access');

This will prevent the PHP file from being executed via a direct HTTP request (if you look at the example blogger file included with Jumi you will see this line). The define statements you have, initialise globals that Joomla! code uses to make sure a request has entered through the right path.

Apart from that, as mentioned by @travega you close of the PHP with ?> before you close the foreach()