doulu7258 2012-10-02 12: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 15: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!

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部