+ Reply to Thread
Results 1 to 8 of 8

Thread: Script Help Please

  1. #1
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Script Help Please

    Needless to say, I have not scripted in PHP for 3 months now and I have found my self to forget the most basic concepts. Could some one please remind me why this is not working?
    PHP Code:
    <?php
    $Info 
    "None";
    function 
    LoadResults() {
     
    $Info "It is Me!";
     return 
    true;
    }

    function 
    LogIpCount() {
     
    $Info "Foriegn!";
     return 
    false;
    }

    if (
    $_SERVER['REMOTE_ADDR']=="000.000.000.000") {LoadResults(); echo "1";}
    else {echo 
    "2"LogIpCount();}

    ?>

    <html>
    meaningless code...
    <body><?php echo $Info?></body>
    </html>
    I was planning to put a simple IP counter for all IP addresses but my own, like a visit counter. Basically, it checks if I am the person on the web site, otherwise it assigns the value "Foriegn!" to the $Info variable which is printed some ways down the page. Even though I have proven that the IF statement evaluates correctly, for some reason, the function is unable to change the value of the variable and output is the default value: "None". Why is that, especially since it can print the default value?
    _____________
    Output: "None"

    Also, does anybody know why in certain pages, like some of the JavaScript games I have been working on, the IDs and getElementById() does not work? Is it due to improperly nested DIV, TABLES, FIELDSETS, ect?
    Last edited by Twinkie; 10-06-2008 at 08:43 PM. Reason: Automerged Doublepost

  2. #2
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: Script Help Please

    PHP Code:
    <?php
    $Info 
    "None";
    function 
    LoadResults() {
     global 
    $Info;
     
    $Info "It is Me!";
     return 
    true;
    }

    function 
    LogIpCount() {
     global 
    $Info;
     
    $Info "Foriegn!";
     return 
    false;
    }

    if (
    $_SERVER['REMOTE_ADDR'] == "000.000.000.000") {
     
    LoadResults();
     echo 
    "1";
    } else {
     echo 
    "2";
     
    LogIpCount();
    }

    ?>
    <html>
    meaningless code...
    <body><?php echo $Info?></body>
    </html>
    Since the variable is set outsite, you need to register this variable as a global for the function to work. You may also use pointers... but that's complex.
    Quote Originally Posted by Twikie
    Also, does anybody know why in certain pages, like some of the JavaScript games I have been working on, the IDs and getElementById() does not work? Is it due to improperly nested DIV, TABLES, FIELDSETS, ect?
    Make sure you are making no mistakes, and look at the javascript error console, it helps.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  3. #3
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant Salvatos is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: Script Help Please

    You could also return $Info instead of true or false I guess.

    Also, please note that it is spelled "Foreign" ;)

  4. #4
    natsuki's Avatar
    natsuki is offline x10 Sophmore natsuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    112

    Re: Script Help Please

    Even if you change a variables content inside a function, the value of the variable will remain unchanged outside the function unless you declare it as global as xav0989 said. The simplest workaround is of course having the function return the value instead as Salvatos said. The other option is to reference the var but it's not optimal.

  5. #5
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Thumbs up Re: Script Help Please

    Thanks so much guys, It is all coming back to me now! If any of you ever need help with JavaScript/AJAX/HTML, you know were to find me.

    Also, the game scripts maybe does contain some errors, but they do not show up in the error console. The script also works perfectly when I use the onclick event (which I hate using), instead of a controlled, script defined event handler. Does anybody know any good JavaScript debuggers that is better than Firefox's error console?

    PS: Now I have to read my whole bible sized PHP reference book again. :pat:
    Last edited by Twinkie; 10-07-2008 at 08:53 PM.

  6. #6
    natsuki's Avatar
    natsuki is offline x10 Sophmore natsuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    112

    Re: Script Help Please

    Quote Originally Posted by Twinkie View Post
    Does anybody know any good JavaScript debuggers that is better than Firefox's error console?
    Woah I didn't know about this one thanks for the info!

  7. #7
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: Script Help Please

    Quote Originally Posted by Twinkie View Post
    Does anybody know any good JavaScript debuggers that is better than Firefox's error console?
    You might want to take a look at javascript debugger or firebug... extensions.

    I've edited the script as you suggested
    PHP Code:
    <?php
    $Info 
    "None";
    function 
    LoadResults() {
     return 
    "It is Me!";
    }

    function 
    LogIpCount() {
     return 
    "Foreign!";
    }

    if (
    $_SERVER['REMOTE_ADDR'] == "000.000.000.000") {
     
    $Info LoadResults();
     echo 
    "1";
    } else {
     echo 
    "2";
     
    $Info LogIpCount();
    }

    ?>
    <html>
    meaningless code...
    <body><?php echo $Info?></body>
    </html>
    And there was a small spelling mistake too!
    Last edited by xav0989; 10-08-2008 at 03:03 PM. Reason: Small spelling mistake
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  8. #8
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Script Help Please

    Thanks a lot for your help guys! I will look into Firebug. My script is working great now :D

+ Reply to Thread

Similar Threads

  1. CRON job : script timeout ?
    By webtomata in forum Free Hosting
    Replies: 4
    Last Post: 09-12-2008, 04:23 PM
  2. Access to 300+ PHP scripts (2500 credits)
    By jonathanyaniv in forum The Marketplace
    Replies: 11
    Last Post: 06-03-2008, 10:58 PM
  3. Replies: 8
    Last Post: 12-03-2007, 04:12 PM
  4. Server UP time Script
    By dharmil in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 04-03-2006, 04:39 PM
  5. CGI - script, Advertisement _HELP.
    By kaliforna in forum Free Hosting
    Replies: 12
    Last Post: 06-02-2005, 06:01 AM

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