Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > PHP > PHP Forum > จะส่งค่า session ไปยัง page ที่ดึงมายังไงครับ พอดีผมอยากทำ menu เปลี่ยนหน้าไม่ต้อง Refresh น่ะครับ


[PHP] จะส่งค่า session ไปยัง page ที่ดึงมายังไงครับ พอดีผมอยากทำ menu เปลี่ยนหน้าไม่ต้อง Refresh น่ะครับ

 
Topic : 129920



โพสกระทู้ ( 126 )
บทความ ( 0 )



สถานะออฟไลน์



อยากทราบว่าเรา จะส่งค่า session ไปยัง page ที่ดึงมายังไงครับ

file_get_contents('pages/page_'.$page.'.php');

พอดีผมอยากทำ menu เปลี่ยนหน้าไม่ต้อง Refresh น่ะครับ

ขอบคุณครับ

ข้อมูลจาก :
https://tutorialzine.com/2009/09/simple-ajax-website-jquery

demo.php
01.<div id="rounded">
02. 
03.<div id="rounded">
04.    <img src="img/top_bg.gif" alt="top" /><div id="main" class="container">
05.    <h1>A simple AJAX driven jQuery website</h1>
06.    <h2>Because simpler is better</h2>
07.     
08.    <ul id="navigation">
09.        <li><a href="#page1">Page 1</a></li>
10.        <li><a href="#page2">Page 2</a></li>
11.        <li><a href="#page3">Page 3</a></li>
12.        <li><a href="#page4">Page 4</a></li>
13.        <li><img id="loading" src="img/ajax_load.gif" alt="loading" /></li>
14.    </ul>
15.     
16.    <div class="clear"></div>
17.     
18.    <div id="pageContent">
19.    Hello, this is a demo for a <a href="http://tutorialzine.com/2009/09/simple-ajax-website-jquery/" target="_blank">Tutorialzine tutorial</a>. To test it, click some of the buttons above. Have a nice stay!</div>
20.     
21.    </div>
22.    <div class="clear"></div>
23.    <img src="img/bottom_bg.gif" alt="bottom" /></div>
24.</div>


Code (JavaScript)
01.$(document).ready(function(){ //executed after the page has loaded
02. 
03.    checkURL(); //check if the URL has a reference to a page and load it
04. 
05.    $('ul li a').click(function (e){    //traverse through all our navigation links..
06. 
07.            checkURL(this.hash);    //.. and assign them a new onclick event, using their own hash as a parameter (#page1 for example)
08. 
09.    });
10. 
11.    setInterval("checkURL()",250);  //check for a change in the URL every 250 ms to detect if the history buttons have been used
12. 
13.});
14. 
15.var lasturl=""; //here we store the current URL hash
16. 
17.function checkURL(hash)
18.{
19.    if(!hash) hash=window.location.hash;    //if no parameter is provided, use the hash value from the current address
20. 
21.    if(hash != lasturl) // if the hash value has changed
22.    {
23.        lasturl=hash;   //update the current hash
24.        loadPage(hash); // and load the new page
25.    }
26.}
27. 
28.function loadPage(url)  //the function that loads pages via AJAX
29.{
30.    url=url.replace('#page','');    //strip the #page part of the hash and leave only the page number
31. 
32.    $('#loading').css('visibility','visible');  //show the rotating gif animation
33. 
34.    $.ajax({    //create an ajax request to load_page.php
35.        type: "POST",
36.        url: "load_page.php",
37.        data: 'page='+url,  //with the page number as a parameter
38.        dataType: "html",   //expect html to be returned
39.        success: function(msg){
40. 
41.            if(parseInt(msg)!=0)    //if no errors
42.            {
43.                $('#pageContent').html(msg);    //load the returned html into pageContet
44.                $('#loading').css('visibility','hidden');   //and hide the rotating gif
45.            }
46.        }
47. 
48.    });
49. 
50.}




load_page.php
1.if(!$_POST['page']) die("0");
2. 
3.$page = (int)$_POST['page'];
4. 
5.if(file_exists('pages/page_'.$page.'.php'))
6.      echo file_get_contents('pages/page_'.$page.'.php');
7. 
8. else echo 'There is no such page!';




Tag : PHP, HTML, CSS, Ajax

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-01-11 11:24:39 By : KenJeRoKung View : 1330 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Session เรียกได้เลยครับ ไม่ต้องส่งค่าตัวแปรครับ

Code
$_SESSION["Session-Name"]


PHP & Session
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-01-12 17:47:51 By : mr.win
 

 

No. 2



โพสกระทู้ ( 126 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2018-01-12 17:47:51
รายละเอียดของการตอบ ::

ผมลองใช้ session แล้วครับ แต่ค่าไม่มาครับ ผมงงมากเลย

session_start() ก็ ใส่แล้ว
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-01-16 13:41:05 By : KenJeRoKung
 

 

No. 3



โพสกระทู้ ( 9,590 )
บทความ ( 2 )



สถานะออฟไลน์


Code (PHP)
1.if(file_exists('pages/page_'.$page.'.php'))
2.echo file_get_contents('pages/page_'.$page.'.php');

ตรงนี้ จะเป็นคนละ session นะครับ เพราะไม่ได้เรียก จาก browser แต่เรืยกจาก server เอง

ต้องใช้ Code (PHP)
1.if(file_exists('pages/page_'.$page.'.php'))
2.  header( 'location: pages/page_'.$page.'.php');

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-01-16 15:01:51 By : Chaidhanan
 

 

No. 4



โพสกระทู้ ( 738 )
บทความ ( 0 )



สถานะออฟไลน์


ใช้ file_get_contents() ไม่น่าจะสร้าง Session จากฝั่ง Client ได้ครับ

เพราะว่า ทางฝั่ง Client ไม่ได้ Request ไฟล์นั้นด้วยตัวเอง หากแต่ว่าสั่งให้ Server ทำการ Execute ไฟล์นั้นๆ

แล้วนำ Content ที่ได้ส่งมองให้ Client

ไม่ลองเขียนฟังชั่นขึ้นมาเองอ่ะครับ

ใช้พวก load() request ไฟล์ไปเลย ไม่ต้องผ่าน php เพื่อให้ไป execute ไฟล์หลายทอดครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-01-17 02:58:53 By : tomrambo
 

 

No. 5



โพสกระทู้ ( 738 )
บทความ ( 0 )



สถานะออฟไลน์


ใช้ file_get_contents() ไม่น่าจะสร้าง Session จากฝั่ง Client ได้ครับ

เพราะว่า ทางฝั่ง Client ไม่ได้ Request ไฟล์นั้นด้วยตัวเอง หากแต่ว่าสั่งให้ Server ทำการ Execute ไฟล์นั้นๆ

แล้วนำ Content ที่ได้ส่งมองให้ Client

วิธีแก้ก็คือให้ใช้ ajax นั่นแหละครับ Request ไฟล์นั้นๆไปเลย ทำเป็นชื่อไฟล์แบบ Dynamic

หรืออาจจะใช้ load() ก็ได้ ไม่จำเป็นต้องผ่าน php เพื่อให้ไป execute ไฟล์หลายทอดครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-01-17 03:07:37 By : tomrambo
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : จะส่งค่า session ไปยัง page ที่ดึงมายังไงครับ พอดีผมอยากทำ menu เปลี่ยนหน้าไม่ต้อง Refresh น่ะครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่