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!

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

报告相同问题?

悬赏问题

  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案