dongyuan1160 2012-06-20 15:52
浏览 79
已采纳

在$ _SESSION中保存页面ID

I am new to sessions, and think I get the basics of them, they seem to act like containers holding information which you can use on at a later stage and are linked to your UID.

I am wondering how I would save the ID of a page (example ID123) on the click of a button, and what exact code I'd have in the header.

Much appreciated in advance!

EDIT:

This is on wordpress, sorry to add this, each page has an 'event ID' I want this to be stored for use later (at a kind of checkout page) sorry for not adding this!

  • 写回答

2条回答 默认 最新

  • droirqk4795 2012-06-20 17:53
    关注

    In wordpress you cannot pass custom url parameters. So you cannot send something like http://yourwordpresswebsite.com/?custom_param='value'

    WOrdpress doesnt allow it. SO if all you want is a Post ID or a Page ID. It is easy to grab in wordpress. Do:

    $val= $post->ID
    

    Thats it and $val is set. The way I do if I have to send any custom parameters to a different file is by sending it as a form variable. There might be better ways but I am new to Wordpress and php too. So this is what I do:

    <?php
    echo "<form action='php_file.php' method='post' name='form_name'>
    <input type='hidden' name='eventid' value='$event_id' />
    <input type='submit' name='submit' value='submit'/>
    </form>";
    
    ?>
    

    If you want this to be your session info you can just add it in your php file where you are collecting the above fields.

    session_start();
    $_SESSION['pageId'] = (int) $_GET['eventid'];
    
    /*  Do not forget to check if the get variable is clean before you perform any operations, use mysql_real_escape_string(). It is a very important security measure. */
    

    This might not be the best approach as I told you I am new to wordpress too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分