session_register()

Discussion in 'PHP' started by gos1, Mar 9, 2006.

  1. #1
    there is a problem at my script. can you please check. It works fine for the first time but when I try to post data again. It always gives the
    you cannot make two requests at that time
    output. I echoed all the variables to see the problem $_SESSION['tarih'] variable is always equals to the $tarih variable. But I want it to be equal to the $tarih varible which is sent in a previous run.
    -------------------------------------------
    <?php
    session_start();
    ?>
    <html>
    <head>
    <title>Process Status</title>
    </head>


    <body bgcolor="#007297" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
    <table width="800" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2" valign="top" rowspan="2"><img src="images/logo.gif" width="340" height="61"></td>
    <td width="344" height="46"></td>
    <td width="54"></td>
    <td width="62"></td>
    </tr>
    <tr>
    <td height="17"></td>
    <td></td>
    <td valign="top"><font color="#FFFFFF"><b><font face="Times New Roman, Times, serif" size="2"><a href="index.php">|
    Home | </a></font></b></font></td>
    </tr>
    <tr>
    <td colspan="5" height="19" valign="top"><img src="images/ayr.gif" width="800" height="19"></td>
    </tr>
    <tr>
    <td height="141" width="127"></td>
    <td colspan="2" valign="middle" align="center">


    <?

    $connect = mysql_connect ("localhost", "root", "molekuler");
    mysql_select_db( "oncead" , $connect ) or die ("DB error!!!".mysql_error());

    $em = $_POST["_email"];
    $wi = $_POST["_width"];
    $he = $_POST["_height"];



    if ( !empty($em) && !empty($wi) && !empty($he))
    {
    $paym = ($wi * $he);

    if ($paym >= 100)
    {

    $tarih = time();
    $tarih1 = time() + 10;
    $ip = $_SERVER['REMOTE_ADDR'];

    if (!empty($_SESSION['tarih']) && $_SESSION['tarih'] < $tarih1)
    {
    echo "you cannot make two requests at that time";
    echo "<BR>";
    echo $_SESSION['tarih'];
    echo "<BR>";
    echo $_SESSION['ip'];
    echo "<BR>";
    echo $tarih1;
    }
    else
    {
    session_register("tarih");
    session_register("ip");
    mysql_query("INSERT INTO _requests ( email , width , height , req , tarih ) VALUES ('".$_POST["_email"]."', '".$_POST["_width"]."', '".$_POST["_height"]."', '".$_POST["_request"]."', '$tarih' )" ) or die (mysql_error());
    echo "Thank you for your request" ;
    }
    }
    else
    {
    echo "Please click back button and fill the form completely..." ;
    }
    }
    else
    {
    echo "width * height must be at least 100";
    }

    ?>


    </td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td height="70"></td>
    <td width="213"></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </table>


    </body>
    </html>
    ---------------------------------
    I am trying to do the same thing (time control to the form script.) For the first time I run this script it worked correctly then always gived the
    -----------------------------------
    you cannot make two requests at that time
    -----------------------------------
    output. After that just wanted to try it and I echoed all the variables. The $_SESSION['tarih'] variable is always equals to
    ------------------
    $tarih1 - 10
    -------------------
    I did not find out where I do the mistake. Why the script is always setting the session variable to tarih at the beginning. ??????
     
    gos1, Mar 9, 2006 IP
  2. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #2
    Sorry, not a PHP expert... and maybe a bit tired to understand 100% what you wrote, but the session variable is set when you first run the script, yes? and will stay that way until the session is destroyed... so you run the script once and the session variable is set... you run it again and checks if it's set and it is. until you destroy the session.

    EDIT: $_SESSION['tarih'] always stays the same and as the original $tarih as it's never altered. $tarih and $tarih1 always change. if you want to change $_SESSION['tarih'] then you need to update with $_SESSION['tarih'] = $tarih; at the end of the run and then this will be used in the next run and updated at the end of that run. and good night now. good luck!

    PS: you might want to edit out your password... or did you change it to something random?
     
    ryan_uk, Mar 9, 2006 IP
  3. sketch

    sketch Well-Known Member

    Messages:
    898
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    148
    #3
    It sounds like your register_globals settings in php.ini is disabled, which is very likely since this is default on unedited installs of PHP 4.2 and up.

    However, unless you're running a version of PHP lower than 4.2.0, you shouldn't even be using session_register since it's deprecated (http://us3.php.net/manual/en/function.session-register.php) . Use $_SESSION['variable'] to store your session variables.
     
    sketch, Mar 10, 2006 IP