assistance with xampp

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

assistance with xampp

Postby itsabilly » 24. June 2010 19:39

Hello all, I come here for assistance, I have been having issues getting a simple script to work in xammp, as well as MAMOP, which leads me to think there is an issue with the
script) When I upload the script to my website, it works with out issues. I check the log for xammp and it tells me undefined variable.

The phpscript is as follow:
Code: Select all
<?php
setcookie ('sitestyle', $set, time()+31536000);
header("Location: $HTTP_REFERER");
?>


the php code on index page is:

Code: Select all
<link rel="stylesheet" type="text/css"    media="screen" title="default" href="<?php echo
(!$sitestyle)?'defaultstyle':$sitestyle ?>.css">

<link rel="alternate stylesheet" type="text/css" media="screen" title="blue" href="blue.css">
<link rel="alternate stylesheet" type="text/css" media="screen" title="pink" href="pink.css">

</head>

<a href="switcher.php?set=default">Default</a>
<br>
<a href="switcher.php?set=blue">Blue</a>
<br>
<a href="switcher.php?set=pink">Pink</a>


as I said it works on myweb site as intended, as I get the same problem/error in logs on both xampp and MAMP, the guys over at MAMP have been no help, so your help is
greatly appreciated!

The script is basically a color changing script, the log keeps pointing to the $HTTP_REFERER in php file as the problem and the $sitestyle, what am I doing wrong?

Thanks in advance!

bill
itsabilly
 
Posts: 1
Joined: 24. June 2010 19:29

Re: assistance with xampp

Postby MegaChriz » 27. June 2010 14:26

I can be wrong, but I think it has something to do with the 'register globals'-setting. If this is turned on, variables in $_GET, $_POST, $_COOKIE, $_SERVER and $_SESSION are automatically set to PHP-variables. For example if $_GET['foo'] exists, the 'register globals'-setting will take care for the existing of a PHP-variable $foo.

In XAMPP, the 'register globals'-setting is turned off by default, because with this setting on you have a high security risc. For example, if you have a website where you can login and you only check if $login is true, then someone can easily login to just set $_GET['login'] to true:
Code: Select all
index.php?login=1

So with the 'register globals'-setting turned off, the variable $sitestyle won't exist. You should point to $_COOKIE['sitestyle'] instead or set $sitestyle to $_COOKIE['sitestyle'].

To improve your code, it's even better to check if a variable exists in PHP, so you don't generate NOTICE-errors. This is possible with the PHP-function isset():
Code: Select all
<?php echo
(!isset($_COOKIE['sitestyle']))?'defaultstyle':$_COOKIE['sitestyle']; ?>

Another handy thing to find errors in your PHP-code is to set the error reporting to the highest level:
Code: Select all
error_reporting(E_ALL | E_STRICT);

This way you can track errors more easily and it helps you to work strict. You should turn this off when your site is going live, because you usually don't want visitors to see PHP-errors.
MegaChriz
 
Posts: 158
Joined: 16. February 2009 15:04
Location: Amersfoort, The Netherlands
Operating System: Mac OS X


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 7 guests