LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP Script Issues (Reading Cookies) (https://www.linuxquestions.org/questions/programming-9/php-script-issues-reading-cookies-456097/)

ReMuSoMeGa 06-18-2006 11:06 PM

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
Code:

<?
include('loadskin.php');
include(''.$path.'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.

loadskin.php
Code:

<?php
$sskin = $_COOKIE["serialdevilskin"];
switch ($sskin){
case 1:
$path = "global/clean_devil/";
break;
case 2:
$path = "global/serialsws/";
break;
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?

Thanks,
-Remus.

j-ray 06-19-2006 07:07 AM

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 ?

ReMuSoMeGa 06-19-2006 11:18 AM

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.

ReMuSoMeGa 06-19-2006 05:49 PM

Well NVM, I solved the problem. I now store information in MySQL tables by IP instead - Works a lot faster than cookies.

doc.nice 06-20-2006 01:09 PM

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.


All times are GMT -5. The time now is 04:55 PM.