dryift6733 2011-02-10 20:38
浏览 30
已采纳

jQuery AJAX和PHP会话问题

Really hope this makes sense and someone can point me in right direction. On a registration page (parent page), when you enter a license code a jQuery ajax success function loads content from another page with an appended url to include a session id:

success: function(data) {
    if (data=="RegisterError") {
        $("#error").show();
        $("#processing").hide();
    } else {
        $("#contain").load("download-software.php?sessionid=xXXX #req");
        }
    }

The page "download-software" has the following PHP referrer check to make sure the content is being requested from the registration page via the session ID and redirects you if it's not:

<?php
$code = $_GET['sessionid'];
if(strcmp( $code , 'xXXX'  ) != 0) {
    header("Location: http://www.someotherpage.com");
}
?>

That works fine. Now what I need to do is in the "download-software #req" content that is loaded into the parent page, have a link that when clicked replaces the "download-software #req" content which has been loaded inside the parent page with content from another page and do the same type of session id check.

I cannot get it to work. I place the following code on the "download-software #req" content for the <a id="beta">beta notes $("#beta").click(function() { $("#req").load("NT7-SP1-Download.php #betaNotes"); });`

I've also tried using the .live function. How do I start a new session and make this work? *answer** I used the live function on the parent page and it works fine. Making it too hard i guess.

  • 写回答

1条回答 默认 最新

  • doulan9287 2011-02-10 23:11
    关注

    I would refrain from using GET query string parameters and use the included PHP session functions.

    use:

    <?php
    
    // initialize the session 
    session_start();
    
    // assignment call
    $_SESSION['key'] = 'value';
    
    ?>
    

    You can retrieve data from the session on the same server in subsequent page requests.

    When you are done with the session, use: session_destroy()

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

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP