PHP : Need some help

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP : Need some help

Postby DutchForce » 31. January 2007 20:27

Hey i've just installed XAMPP and everything is working fine exept for the PHP part....
I've openen up a browser and loaded the page and tryed to click some php links but they just go back to the starting page. Can anybody maybe tell me what the problem is? I know its not the code because i've been using it for ages now.

this makes the site always open with same content
Code: Select all
<?php if ($index=="") $index="news"; if ($menu=="") $menu="menu1"; ?>

This is the link so when i click the link it just loads the starting content again.....
Code: Select all
<a href="index.php?index=staff&menu=menu1">> Staff</a><br>

Code: Select all
<? if (!$index) {$index="index";}include ($index.'.txt'); ?>
DutchForce
 
Posts: 10
Joined: 31. January 2007 20:18

Postby Wiedmann » 31. January 2007 21:02

Code: Select all
<?php if ($index=="") $index="news"; if ($menu=="") $menu="menu1"; ?>

Well, in the first step you compare a the variable "$index" with the string "".
But this variable is still undefined in this stage of the script.
--> I don't see any: $index = "foo";

You should set your error_reporting to E_ALL, to see such errors.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby DutchForce » 31. January 2007 21:31

yeh it is undifined so if people just enter www.blablabla.com it will still open news.txt

and i don''t get errors
DutchForce
 
Posts: 10
Joined: 31. January 2007 20:18

Postby Wiedmann » 31. January 2007 22:02

and i don''t get errors

I'm sure you have not changed your error_reporting as I advised you...


yeh it is undifined

Right, and you never put another value into this variable. Thus you always get "news.txt".

You remember?
Wiedmann wrote:--> I don't see any: $index = "foo";
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby DutchForce » 31. January 2007 22:06

yes i get other pages look at the the 3rd code i put in
its saying if index is staff it will load staff.txt

i've had this site up and running on a domain before and it all worked... but now i tought lets just complete the site offline so i can work and test even without inet connection
DutchForce
 
Posts: 10
Joined: 31. January 2007 20:18

Postby DutchForce » 31. January 2007 22:10

here is the site www.stuger.100webspace.net
its the exact same code and all links work perfectly
DutchForce
 
Posts: 10
Joined: 31. January 2007 20:18

Postby Wiedmann » 31. January 2007 22:28

its the exact same code and all links work perfectly

No. It's works accidentally on this special server ;-). Such a simple code must work on all servers to be "perfect".

its saying if index is staff it will load staff.txt

And where in your code did you assign the value "staff" to your variable?

BTW:
I think you should read the PHP-Manual about "Variables from outside PHP":
http://de.php.net/manual/en/language.va ... ternal.php
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby DutchForce » 31. January 2007 22:30

i assigned it to index somewhere around here
Code: Select all
<a href="index.php?index=staff

and it worked on all servers i've been on
DutchForce
 
Posts: 10
Joined: 31. January 2007 20:18

Postby Wiedmann » 31. January 2007 22:36

i assigned it to index somewhere around here

You have clicked the link above?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby DutchForce » 31. January 2007 22:38

yes i have.... and what about that??
DutchForce
 
Posts: 10
Joined: 31. January 2007 20:18

Postby Wiedmann » 31. January 2007 22:53

and what about that??

Just read this page and learn how to access "external variables"... :-/


BTW a hint:
Code: Select all
<a href="index.php?index=staff&amp;menu=menu1">Staff</a>

This link don't define the PHP variables "$index" and "$menu" in a standard configuration. You can access the values through the $_GET array:
Code: Select all
<?php
    if (empty($_GET['index'])) {
        $index = 'news';
    } else {
        $index = $_GET['index'];
    }

    if (empty($_GET['menu'])) {
        $menu = 'menu1';
    } else {
        $menu = $_GET['menu'];
    }
?>
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby DutchForce » 31. January 2007 23:01

omg..... i've been using that code for 3 years now it always worked before so why is it all of the sudden wrong???

your just showing how to make a long code .... where i tryed to make it as small as possible.

Code: Select all
<?php if ($index=="") $index="news"; if ($menu=="") $menu="menu1"; ?>

here if index = empty then index = news
lets not worry about the menu thing.

Code: Select all
<a href="index.php?index=staff&menu=menu1">> Staff</a><br>

this is the link in the webpage saying index = staff

Code: Select all
<? if (!$index) {$index="index";}include ($index.'.txt'); ?>

here it is saying index = the text i gave it then include text+.txt
so if index = staff it loads up staff.txt in de content area wich means i only have to give all links the index and it loads the txt file of it
DutchForce
 
Posts: 10
Joined: 31. January 2007 20:18

Postby Wiedmann » 31. January 2007 23:18

your just showing how to make a long code

No, how to make it correct.

where i tryed to make it as small as possible.

No, there is also a way to write a correct short code. But first learn how to write it correct ;-)


Code: Select all
<? if (!$index) {$index="index";}include ($index.'.txt'); ?>

This code is really a security risc for your server...

Same as above:
Code: Select all
<?php
    if (empty($_GET['index'])) {
        $index = 'index';
    } else {
        $index = $_GET['index'];
    }
    include basename($index.'.txt');
?>


BTW:
You should not use "<?". It does not work on all servers and in XMP capable editors. Use "<?php" instead.

BTW:
<a href="index.php?index=staff&menu=menu1">> Staff</a><br>

This Link is wrong. correct is:
Code: Select all
<a href="index.php?index=staff&amp;menu=menu1"> Staff</a><br>
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby DutchForce » 31. January 2007 23:20

hmmm so your saying it really not working on all servers....

is there a easy way to fix it without changing all the code.... its just for offline testing now anyways
DutchForce
 
Posts: 10
Joined: 31. January 2007 20:18

Postby Wiedmann » 31. January 2007 23:28

s there a easy way to fix it without changing all the code

http://de.php.net/manual/en/security.globals.php

But you should really correct your code (and with PHP6 you can't change this setting in PHP anymore).
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Next

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 139 guests