简体   繁体   中英

PHP Sessions on facebook Tab application

i 've built an app on facebook, and i am trying to insert correct info on database. The info gets inserted,but something has gone wrong with the sessions in my code(not facebook sessions for users) It seems that if two different machines have entered the iframe app,it only creates 1 session and it does not store product correcty.

Here: (first page) - product-check.php I start the session.

session_start();

Then (Second Page) - form.php :

    require 'facebook.php';
    session_start();
   if (isset($_REQUEST['product']) == NULL)
   {
   header ("location: product-check.php");
   }
   else
   {
   $product = $_REQUEST['product'];
   //let's start the session
   //Posted Values stored in session
   $_SESSION['product'] = $product;

Then on third page i make the insert with values from both pages - product-check and form.

    session_start();
    $link = mysql_connect('With the right credentials') or die(mysql_error());
    mysql_set_charset('utf8',$link);
    $db_selected = mysql_select_db('application', $link);
   $product = mysql_real_escape_string($_SESSION['product']);
   if (isset($_POST['name'])){$name = mysql_real_escape_string($_POST['name']);}   
   if (isset($_POST['surname'])){$surname = mysql_real_escape_string($_POST['surname']);} 
   if (isset($_POST['email'])){$email = mysql_real_escape_string($_POST['email']);}
   if (isset($_POST['term'])){$accept_terms =   mysql_real_escape_string("N");}else{$accept_terms = mysql_real_escape_string("Y");}
   if (isset($_POST['contact'])){$accept_newsletter =   mysql_real_escape_string("Y");}else{$accept_newsletter = mysql_real_escape_string("N");}
   $query_insert = "INSERT INTO app(database fields) 
     VALUES(the above values i have declared)";
     $result = mysql_query($query_insert);
     mysql_close($link);
      session_destroy();

That is it.But not all of the products from product-check.php appear in database.

Ok,so i tried another way that works.This time i did not use sessions to pass values,I used hidden fields instead.

I removed the:

    session_start();

part from all the pages and everything that had to do with sessions,and then i created hidden fields that I used for posting values like so:

    <input type="hidden" name="productselect" value="<?php echo $variable ?>">

and then on the page posted i used a simple post :

   $product = $_POST['productselect']

It worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM