doulu7258 2012-10-02 20:32
浏览 36
已采纳

Facebook选项卡上的PHP会话

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.

  • 写回答

1条回答 默认 最新

  • dpp78272 2012-10-02 23:43
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理