Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


HTML proper redirection status code?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Servant of the Lord   Crossbones+   -  Reputation: 20945

Like
0Likes
Like

Posted 21 August 2012 - 10:42 AM

Hello - I'm working on some features for my website, and I have a few questions about redirection.

Whenever the user visits a certain page, I want the following things to happen:
A) A (hidden) counter is incremented, so I know how many times that specific page was visited.
B) The user gets redirected to a new page.

Since the page wasn't "moved", status codes 301 and 302 don't really make sense.
Am I understanding that 303 is the best code to send to the user's web browser?

Something like:
header("HTTP/1.1 303 See Other");
header("Location: http://www.example.com/otherpage.php");

The redirection destination page may be on a different website, depending on which page is visited.

I'm not supposed to put any PHP or HTML code before the header() stuff... but can I add PHP code after the header() calls, to increment the counter?
[Edit:] Ah, I'm not supposed to put any PHP code that outputs text (or other content), right? Non-outputting PHP is fine?

Also, should I save user visits to the MySQL database, or to just a text file? Either would work, but which would you personally use?

Edited by Servant of the Lord, 21 August 2012 - 10:48 AM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


Sponsor:

#2 Madhed   Crossbones+   -  Reputation: 3129

Like
0Likes
Like

Posted 21 August 2012 - 11:32 AM

I would use the database for that.
Specifically, insert an entry per visit into a table that you can aggregate from time to time.

Also I think you shouldn't have to redirect at all if it is just for counting page visits.

As to your question: Yes you can't output text before the headers are set because in html the headers always have to be sent before any content.

Edit: Didn't read your reasons for redirecting

Edited by Madhed, 21 August 2012 - 11:33 AM.


#3 wicked357   Members   -  Reputation: 1273

Like
0Likes
Like

Posted 21 August 2012 - 11:40 AM

You could do something like

<?php

// Connect to DB

// Increment hits by 1

// Redirect to page
header(...);

?>

or redirect then on the otherpage.php you can increment and put that in the db

I would personally use MySQL for keeping track of page hits.

Edited by wicked357, 21 August 2012 - 11:42 AM.


#4 Servant of the Lord   Crossbones+   -  Reputation: 20945

Like
0Likes
Like

Posted 21 August 2012 - 04:47 PM

Thanks guys, working on implementing it. So HTTP status code 303: is that the correct one for my needs? Redirection not because something moved, but because html file A's purpose is to point to html file B?

 

Unrelated question: How do I set up a domain name (otherDomain.com) to point to another domain's sub-directory (mainDomain.com/location/), but continuing to have URL listed as "otherDomain.com" as the user is exploring that site?

I have my main site, www.myname.com, and I'd like www.myname.com/myGameName to be the URL of my game's website. (The reason why I want it to be "contained" within the first site, is because the site is powered by the same files, and it's really one site). However, I want the domain name to look nice for users, so they see: "www.myGameName.com/about-this-game.html" instead of "www.myname.com/myGameName/about-this-game.html".

Any ideas?


[Edit:] Second question resolved, using this article.

Edited by Servant of the Lord, 21 August 2012 - 09:50 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 TMKCodes   Members   -  Reputation: 271

Like
1Likes
Like

Posted 22 August 2012 - 05:01 AM

3xx codes refer to redirection. 303 "see other" means that the response to request can be found in different URI and should be retrieved with the GET method. Though some older browsers might not support 303, then you should use 302 "found".




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS