+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP Variables Issue

  1. #1
    prateems32 is offline x10Hosting Member prateems32 is an unknown quantity at this point
    Join Date
    Feb 2011
    Posts
    6

    PHP Variables Issue

    I'm having a problem with the following code:

    PHP Code:
    <?php # Script - index.php

    if (isset($var)) {
       
    // Check to see if the variable $var is given a value...
       /* ... */ # <-- Bunch of PHP code to be executed if condition is met.
    } else {
       
    // If $var hasn't been defined...
       
    echo "<a href=\"index.php?var=yes\">Set variable var=\"Yes\"</a>";
    }

    ?>
    Now, I'm trying to migrate web-hosts from a different host to x10hosting, but I need to be able to run this kind of script. x10hosting has better features offered, so I definitely want to stick to it. On my prior web-host, this script works perfectly fine with no reported errors, but upon uploading of the exact same file to this server, I run into the following problem:

    On loading the page (index.php), it executes the else part of the if() statement, but when I click on the link, it does not work as it should. It keeps taking me to the correct page (index.php?var=yes), where $var is defined, but continues running the else part of the if() statement.

    This is a big issue for me because my script uses a bunch of these kinds of statements.

    Any help would be appreciated. Thanks!

    - Prateem Shrestha

    ---------- Post added at 05:22 AM ---------- Previous post was at 05:10 AM ----------

    Based on the related threads links, it's probably because register_globals is turned off...

    I'll try using $_GET['var'] in a temporary version of my script to see if it works and update accordingly. Cheers

    ---------- Post added at 05:28 AM ---------- Previous post was at 05:22 AM ----------

    Yep, using $_GET['var'] worked perfectly fine.
    Now I know. :P
    Last edited by prateems32; 02-19-2011 at 12:26 PM.

  2. #2
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: PHP Variables Issue

    Why was register_globals turned on on your old host?! It can lead to many problems and sometimes security flaws - always use $_GET or $_POST accordingly.

    ~Callum
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  3. #3
    prateems32 is offline x10Hosting Member prateems32 is an unknown quantity at this point
    Join Date
    Feb 2011
    Posts
    6

    Re: PHP Variables Issue

    Can it really? I'm not too knowledgeable about the issue. Well, the more I know, heh.
    Mmm I figured it'll probably be good practice for me to always use $_GET['var'] instead of just $var when I need to, after I made the changes.

    Not too sure why it was turned on for my previous host, though.

+ Reply to Thread

Similar Threads

  1. PHP variables are not getting picked up
    By itwizard in forum Free Hosting
    Replies: 10
    Last Post: 12-31-2009, 04:10 AM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. [php] variables
    By taekwondokid42 in forum Programming Help
    Replies: 4
    Last Post: 04-14-2008, 04:44 PM
  4. PHP Variables
    By ScottyB in forum Programming Help
    Replies: 8
    Last Post: 03-23-2008, 06:04 PM
  5. variables globales
    By oregonsv in forum Ayuda Web
    Replies: 0
    Last Post: 02-07-2008, 09:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers