Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-18-2006, 11:06 PM   #1
LQ Newbie
Registered: Jun 2006
Posts: 7

Rep: Reputation: 0
Exclamation PHP Script Issues (Reading Cookies)

Hi, On my site im trying to make a skin selector. The skin chooser saves your preference in a cookie.

here is my index.php

loadskin.php reads your cookie, and determines what skin you wanted to use. It then loads
the filepath to the template file and saves it as $path.

$sskin = $_COOKIE["serialdevilskin"];
switch ($sskin){
case 1:
$path = "global/clean_devil/";
case 2:
$path = "global/serialsws/";
if(($sskin <> 1) && ($skin <> 2)){
$sskin = "1";

The script works perfectly, it remembers what skin you chose, and it loads it correctly.
Now, here is the problem.

When ever I enable my new template system, my server loads go over 20 all of a sudden, and it crashes my server.

I am getting extremely high traffic, 30 queries a second, 70k unique hits daily. My server is getting a lot of traffic as it is, but my site uses a very well made search engine with 5 hour caching. Server loads are under 0.5 during peak hours.

Its obvious that the skin selector is causing the loads.

Can someone please help me fix this problem. Is there a better way to write this code without causing such a high load?

Old 06-19-2006, 07:07 AM   #2
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,550

Rep: Reputation: 136Reputation: 136
i would place
if(($sskin <> 1) && ($skin <> 2)){
$sskin = "1";
before the switch. Now it is placed behind the last break - maybe this is causing an internal error.
Is there a typo in the 2nd comparison ?
Old 06-19-2006, 11:18 AM   #3
LQ Newbie
Registered: Jun 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Yea, I just noticed that the IF statement was within the switch.

I moved it after, but I am still having the high server load issues.
Old 06-19-2006, 05:49 PM   #4
LQ Newbie
Registered: Jun 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Well NVM, I solved the problem. I now store information in MySQL tables by IP instead - Works a lot faster than cookies.
Old 06-20-2006, 01:09 PM   #5
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274

Rep: Reputation: 34
well, maybe works, but what for users having a dial up connection, thus getting a new IP whenever they connect to the internet (or DSL, at least in germany, many providers disconnect after 24 hours).

Normally, the php cookie code doesn't make such load problems, on my site it works without problems.
maybe your cookie SET-code is buggy?
if you can post it, I'll have a glance on it.

PS: why the empty string before $path in your include statement? include($path.'index.php') should be enough.


cookies, php, skin

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
issues with mirc script accessing our php script dtra Linux - Software 2 07-02-2005 04:30 PM
Reading cookies crazy diamond General 3 10-13-2004 11:12 AM
cookies in php RazorKnight Programming 1 10-08-2004 04:31 AM
PHP - Cookies, unserialize() dhbiker Programming 1 07-28-2004 02:18 PM
PHP and cookies. jacksmash Programming 13 04-02-2004 09:01 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration