PHP session

For Joomla! 1.0 Coding related discussions.
Locked
User avatar
pelloq1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 145
Joined: Sat Dec 16, 2006 7:42 am
Location: Switzerland

PHP session

Post by pelloq1 » Wed Apr 23, 2008 3:23 pm

Hello,

How can I use the php session functions.

My module dont restore variables stocked via $_SESSION['myVar'] = "value" ;


???

Cedric

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: PHP session

Post by dam-man » Wed Apr 23, 2008 3:51 pm

Hi

Joomla! 1.0 is not starting a session like you want. So what you want is not working.
Take a look at virtuemart, they're starting a session right there ;)

And a small example that is wrking on my localhost:

Code: Select all

<?php

## Check if Joomla enters this page, if not? Die this script immediatly.
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

## Starting a session
session_start();

global $database;

## Get the function from the URL.
$func = mosGetParam( $_GET, 'func' );

## If the session didn't started, stop the script.
if( empty( $_SESSION ) || session_id() == '') {

	echo "Something went wrong.."; 
}

## Switch Functions here.
switch ($func) {

   case "check":
	check();
   break;
   
   case "formsucces":
	formsucces();
   break;   
   
   default:
    form();
}

function check(){

echo "Your Name: ".$_SESSION['name']."<br>";
echo "Your Email: ".$_SESSION['email']."<br>";

}

function formsucces(){

$_SESSION['name']  = mosGetParam( $_REQUEST, 'name') ;
$_SESSION['email'] = mosGetParam( $_REQUEST, 'email') ;

echo "Your Form is submitted Succesfull!";
?>
<a href="index.php?option=com_dailymessage&Itemid=26&func=check" target="_self">Ga verder met testen!</a>
<?php
}

function form() { ?>

<h1 class=contentheading>Test Het Script
</h1>
<form action="<?php echo sefRelToAbs( 'index.php?option=com_dailymessage&func=formsucces'); ?>" method="post" name="S2Form">
<table width=100% border=0 cellspacing=1 cellpadding=0>
  <tr>
	<td width=25%>Naam</td>
	<td width=22%><input type="text" size="30" class="inputbox" name="name" value="<?php echo mosGetParam( $_POST, 'name'); ?>" /></td>
	<td width=53% rowspan="5" align="left" valign="top">&nbsp;</td>
  </tr>
  <tr>
	<td>E-mail Adres</td>
	<td><input type="text" class="inputbox" size="30" name="email" value="<?php echo mosGetParam( $_POST, 'email'); ?>" /></td>
  </tr>
  <tr>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
  </tr>
  <tr>
	<td>&nbsp;</td>
	<td><input type="submit" class="button" name="Submit" value="Test Snel" /></td>
  </tr>
  <tr>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
  </tr>
</table>
</form>
		
<?php } 



?>
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards

User avatar
pelloq1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 145
Joined: Sat Dec 16, 2006 7:42 am
Location: Switzerland

Re: PHP session

Post by pelloq1 » Wed Apr 23, 2008 4:02 pm

Hello,

I have learn the the

## Starting a session
session_start();

function must allway placed at the start (before php write anything in the browser) of the file ... Can I set the session_start in a module ?????

Cédric

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: PHP session

Post by dam-man » Wed Apr 23, 2008 4:09 pm

Session must be started before output, that's correct.
Below is no output, but PHP:
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
OUtput is when you write something to screens like HTML

Just give it a try in your module ;)
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards

User avatar
pelloq1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 145
Joined: Sat Dec 16, 2006 7:42 am
Location: Switzerland

Re: PHP session

Post by pelloq1 » Wed Apr 23, 2008 4:24 pm

Ok I go to test it, but I dont understand that we send the session_start because before the draw of my module, it's many ouput in html (other modules, template ...)

Ced

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: PHP session

Post by dam-man » Thu Apr 24, 2008 6:34 am

Try it, in my component it works great.
I can make a webshop for a specific client now
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards

User avatar
pelloq1
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 145
Joined: Sat Dec 16, 2006 7:42 am
Location: Switzerland

Re: PHP session

Post by pelloq1 » Thu Apr 24, 2008 5:19 pm

Hello,

YES ! It's work.

Thank you

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: PHP session

Post by dam-man » Thu Apr 24, 2008 6:12 pm

Great!

Good luck with your site and module!
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards


Locked

Return to “Joomla! 1.0 Coding”