You are here: Re: My SESSION control is not working ... PLEASE HELP « All PHP « IT news, forums, messages
Re: My SESSION control is not working ... PLEASE HELP

Posted by Joseph Melnick on 10/10/50 11:19

Ivan Wrote:

"Ivan // INSIDE" <ivan@inside.com.hr> wrote in message
news:d9f0jk$a71$1@ss405.t-com.hr...
> Here is the code of session.php :
>
> <?php
> // SESION TEST
>
> session_start();
> session_name("id");
> session_cache_expire(15);
>
> if (isset($id)) {
>
> session_id($id);
>
> // Pogledaj jel triger tamo
> $triger = $_POST['triger1'];
>
> if ($triger == "1") {
>
> // Ulovi iz forme
> $po1 = $_POST['polje1'];
> $po2 = $_POST['polje2'];
>
> // Registriraj nove $_SESSION
> $_SESSION[p1] = $po1;
change to this:
$_SESSION['p1'] = $po1;
> $_SESSION[p2] = $po2;
change to this:
$_SESSION['p2'] = $po2;
> }
>
> }
> else {
> $id = session_id(md5(uniqid(rand(), true)));
> header("Location: test1.php?".session_name()."=".session_id());
> }
>
> ?>
>
>
>
> Here is the code of input form :
>
> <?php include('session.php'); ?>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html>
> <head>
> <title>Session test</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> </head>
>
> <body>
> <div align="center">
> <form name="form1" method="post" action="test2.php<?php
> echo'?'.session_name().'='.session_id(); ?>">
> <input name="triger1" type="hidden" value="1">
> <table width="500" border="0" cellspacing="5">
> <tr>
> <td width="100">polje 1 </td>
> <td width="390"><input type="text" name="polje1"></td>
> </tr>
> <tr>
> <td>polje 2 </td>
> <td><input type="text" name="polje2"></td>
> </tr>
> <tr>
> <td>&nbsp;</td>
> <td><input type="submit" name="Submit" value="&Scaron;alji
> &gt;&gt;"></td>
> </tr>
> </table>
> </form>
> </div>
> </body>
> </html>
>
>
> Here is the output ( test2.php ) where everything works fine :
>
> <?php
> include('session.php');
>
> print_r ($_SESSION['p1']);
> echo "<br><br>";
> print_r ($_SESSION['p2']);
> echo "<br><br>";
>
> echo "<a href='test3.php?".session_name()."=".session_id()."'>Test3</a>";
> ?>
>
>
>
> And here are code from test3.php and test4.php and this is not working !!!
>
> <?php
> include('session.php');
>
>
> print_r ($_SESSION['p1']);
> echo "<br><br>";
> print_r ($_SESSION['p2']);
>
> echo "<a href='test4.php?".session_name()."=".session_id()."'>Test3</a>";
> ?>
>
>
>
> Now any idea why is not showing anything on pages test3 and test4 ...
> where did I go wrong ?
>
> Please help :(
>
> Ivan

1, quote key values in arrays.
2, if you are posting values you want to keep track of. do not use get
variables in your form action where your form method is POST.

Rather than do this:

<?php echo'?'.session_name().'='.session_id(); ?>

create another hidden input field in your form.

<input type="hidden' name='<?php session_name(); ?>' value='<?php
session_id(); ?>'>

Please Note: You do not need to do this hidden input as session_id() and
session_name() will be available to each of your scripts where your
session.php script is included.

Joseph Melnick
JM Web Consultants
Toronto, ON, Canada
http://www.jphp.com/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация