473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can PHP know when a page is refreshed?

epots9
1,351 Expert 1GB
i was wondering if there is a way in php to figure out if the page was refreshed or it came from another page?
Jun 1 '07 #1
7 5763
pbmods
5,821 Expert 4TB
Check out $_SERVER['HTTP_REFERER'].
Jun 1 '07 #2
ronnil
134 Expert 100+
something like this

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if($_SERVER['HTTP_REFERER'] != $_SERVER['SCRIPT_URI'])
  3. {
  4.     //This page was loaded from another page
  5. } else {
  6.    //The page loaded itself
  7. }
  8. ?>
Don't think there's a problem with $_GET data, but not sure
Jun 1 '07 #3
Motoma
3,237 Expert 2GB
something like this

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if($_SERVER['HTTP_REFERER'] != $_SERVER['SCRIPT_URI'])
  3. {
  4.     //This page was loaded from another page
  5. } else {
  6.    //The page loaded itself
  7. }
  8. ?>
Don't think there's a problem with $_GET data, but not sure
Good one ronnil! Thanks for posting, I hope to see you around here more often!
Jun 2 '07 #4
pbmods
5,821 Expert 4TB
Don't think there's a problem with $_GET data, but not sure
GET variables will appear in $_SERVER['REQUEST_URI'], but not in $_SERVER['SCRIPT_URI'].
Jun 2 '07 #5
epots9
1,351 Expert 1GB
i still can't get it to work. if it is redirected by another page i go my tasks and set [PHP]$_SERVER["HTTP_REFERER"] = "";[/PHP]

but that doesn't work, cuz when i hit refresh the server overwrites it and sets it back to the value indicating that it came from another page once again.

how can i counter this?
Jun 4 '07 #6
Motoma
3,237 Expert 2GB
i still can't get it to work. if it is redirected by another page i go my tasks and set [PHP]$_SERVER["HTTP_REFERER"] = "";[/PHP]

but that doesn't work, cuz when i hit refresh the server overwrites it and sets it back to the value indicating that it came from another page once again.

how can i counter this?
A quick and dirty solution would be to set the current page in a session variable. At the load of each page, make sure that the referer and that session variable match, then set the session variable again. This will not work for pages that link to themselves though.
Jun 4 '07 #7
epots9
1,351 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. location.href=location.href
seems to be working for me now..
Jun 4 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Patrick Delifer | last post by:
Is there a way to not let a page scroll back to the top if the user has scrolled down and the page is refreshed? Users are selecting Datagrid items and they are always brought back to the top when...
0
by: Alfons Puig | last post by:
I have a container page with 3 frames (Header, left frame and right frame) In the right frame I load an aspx page having a boounded datagrid with some column templates having a DopDownList in the...
1
by: abdul bari | last post by:
Hi I have a standard html form which is generated by an XSL sheet. The form data is submitted to the server and is passed on to file.aspx for processing. However file.aspx is refreshed every 5...
3
by: IGotYourDotNet | last post by:
Let me just start by saying taken over someones else code that they wrote just for them to understand(no comments, documentation NOTHING) is a task on in itself. anyway, i have a page that needs to...
1
by: Mike Grace | last post by:
Hi, I have a gridview which is using a SqlDataSource to update a table. The SqlDatasource is using a stored procedure to update the table. If I edit a row, change a value and click update...
0
by: SIXFACESANKAR | last post by:
Hi, In my application, once the user logs in code is written in session_onstart to update / insert the user status . Also there is code written in session_onend to update the user status again....
3
by: msinghal | last post by:
hi, I am facing one problem which is related to AJAX. I have a html page which has some links. When the page is refreshed using AJAX then if some new new link is added to the page on this refresh,...
2
vijcbe
by: vijcbe | last post by:
Hello friends, I am having a big time problem. I have a list of textboxes, radios, etc., in a login page for the user to enter his/her data. I have two drop downs, in which the second one is...
3
by: Mythilisg | last post by:
hi, i'm working in asp.net with c#. i hav one dropdownlist with some options which is similar to Security Questions in yahoo mail. I hav one option called "If Others". When the user selects this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.