473,397 Members | 2,116 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,397 software developers and data experts.

How to redirect a page after 3 views

142 100+
Hi,

I have page x. when you try to visit page x for the 3rd time it must go to page y?

I have no idea how this work or should work, can someone please give me some ideas, as I say I don't even know the first line of coding as I never tried, seen or work with something like this.

I will be able to do it with cookies, but if the persons disable his cookies then it will not work and I need to make it php.

Kind Regards
Louwrens
Jun 27 '07 #1
5 1355
shoonya
161 100+
okk

if you dont want to use cookies then you may have to use data base
because even the php sessions maintains the cookie
you can have a temporary counter in database and increment it every time a user views the page
and then redirect him accordingly

but then even simple refreshing will increase the count

shoonya
Jun 27 '07 #2
Atli
5,058 Expert 4TB
I would recommend using Sessions. Although, as shoonya said, they use cookies, they will work even if cookies are disabled. Sessions can go as far as hashing the session ID into the URL before giving up.

This is incredibly simple using Sessions. For example:
Expand|Select|Wrap|Line Numbers
  1. // Start session
  2. session_start();
  3.  
  4. // Check if the session var exists.
  5. if(isset($_SESSION['visitCount'])){
  6.   // Increment the count
  7.   $_SESSION['visitCount'] += 1;
  8.  
  9.   // Check if it has reached the max (3)
  10.   if($_SESSION['visitCount'] >= 3) {
  11.     header("Location: www.google.com");
  12.   }
  13. }
  14.  
  15. // Create the session var
  16. else {
  17.   $_SESSION['visitCount'] = 1;
  18. }
  19.  
Jun 27 '07 #3
shoonya
161 100+
@ atil

how will the php session handler react, when the cookies are deleted while the session is alive ??

shoonya
Jun 28 '07 #4
webandwe
142 100+
Thanks Atil,



(this message is not to short)
Jun 28 '07 #5
Atli
5,058 Expert 4TB
Happy to help.

@ shoonya
PHP, as a sever-side language, can manipulate HTTP Headers, and so it can use HTTP POST and GET to pass along the SESSIONID.
It is not uncommon to see the PHPSESSIONID variable being passed in the URL when browsing a PHP page, as the Cookie is somewhat unreliable and can apparently be left out, which PHP reacts to by passing the ID by alternate means.
Jun 28 '07 #6

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

Similar topics

10
by: Bob Garbados | last post by:
forgive my ignorance, as I'm new to php coming from a ms background... If I create a page named redirect.php and it's only content is: <?php header("Location: http://www.google.com"); ?>...
7
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script...
13
by: Tim | last post by:
Hello, Is there a way to "cancel" a response.Redirect? For example, in the code below, could I insert anything in the Catch statement that would cancel the redirect and resume flow after the...
4
by: bnob | last post by:
In a Button clik event I have this code at the end of the event Response.Redirect("Page.aspx") But in this event I must show a message before redirect to the Page.aspx. I use to show Message...
5
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
4
by: Steve | last post by:
I thought that this was available for all elements in Firefox, but recently had a page where a div didn't have it. I put in an id style for it, thinking that would do the trick, but it didn't. ...
5
by: cforcloud karulvan | last post by:
hi all, i am working on a ajax calendar program, where the user will click on a date and its corresponding event list will be displayed beside it (similar to http://www.google.com/calendar)....
8
by: Darrel | last post by:
I'm helping convert a 300+ page .html site into an ASP.net site. The client wants to set up 301 redirects for all of the old html pages. I've used ISAPI for this type of thing in the past, as it...
1
by: helraizer1 | last post by:
Hi folks, I apologise for the thread title, couldn't think of a suitable one. At the moment I have made a mini shoutbox that can be used on myspace, or similar. The image is then shown on the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.