FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP variable problem





Magicman
Code:
<html>
<head>
     <title>test.php</title>
</head>
<body>
<?php
if ($page=="one")
echo "<h2>Test One</h2>
<P>TESTINGTESTING</p>";

elseif ($page=="two")
echo "<h2>Test Two</h2>
<p>TESTING2TESTING2TESTING2</p>";
else
echo "<h1>Main</h1>
<p>Mainmainmainmainmain</p>";

?>

</body>
</html>


This is my basic code I'm using on my page. When the url reads "test.php?page=two" it should show whats under that within the code. However it shows the default text (Main). This code worked on another server but doesnt work here. I don't know much about php so maybe theres something I have wrong here. Could you tell me whats going on?
mathiaus
Global vars isn't on here. You need to use $_GET['page']. This is for security reasons.
Daniel15
Like mathiaus said, you'll need to use $_GET['page'] (as you should be doing already), as global vars are disabled here for security purposes.

Maybe you want to do something like:
Code:

<html>
<head>
     <title>test.php</title>
</head>
<body>
<?php
switch ($_GET['page']) {
     case "one":
          echo "<h2>Test One</h2>
          <P>TESTINGTESTING</p>";
          break;

     case "two":
          echo "<h2>Test Two</h2>
          <p>TESTING2TESTING2TESTING2</p>";
          break;

     default:
          echo "<h1>Main</h1>
          <p>Mainmainmainmainmain</p>";
          break;
}

?>

</body>
</html>
Magicman
Ok thanks alot. I'm just adding
Code:
$page = $_GET["page"]
to the begining of my code and it works fine now.
Marston
I'm unaware as to why two moderators wouldn't post the obvious solution to this problem (a solution which was posted in the announcement as to why global_vars was disabled).

In the future, you could just put this in your .htaccess file:
Code:
php_flag register_globals on
mathiaus
That would enable global vars for his whole account (or directory depending on location of .htaccess file). The use of the one line of code he now uses is a more secure method for that one page and the rest of his account.

Solved
-close-
Related topics
Php, mime_content_type() problem
Countdown Javascript with PHP variables
storing current page address as php variable
Need Help integrating php variable into mySQL SELECT query
PHP script problem
Getting PHP variable to work in FCKeditor
Stats problem - php execution problem (MOD Assist Required)
php msql problem
PHP: fopen('./directory/$variable'); Problem
php mail(); problem... half fixed?
PHP noob problem
A variable number of inputs for PHP to insert MYSQL
PHP Includes Problem
removing DirectAdmin part of URL makes php code work
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.