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 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢