SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why does this not return true?

    when I use this code and pass the uId of 55 I expect it to return "cool".

    but I get "not" when I type

    http://myurl.com/test.php?uId=55

    any ideas.


    Code:

    PHP Code:
    <?php 

    $uId 
    $_GET['uId']; 

    function 
    Secure(){ 
       if(
    $uId == 55){ 
          return 
    true
       } 


    if(
    Secure()){ 
       echo 
    "cool"
    }else{ 
       echo 
    "not"

    ?>

    Please help

  2. #2
    SitePoint Member
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to pass $uId as a parameter in the function

    PHP Code:
    <?php
    function Secure($uId)
    {
       if(
    $uId == 55)
       {
          return 
    true;
       }
    }
    ?>
    or you set $uId as global inside the function
    PHP Code:
    <?php
    function Secure(){
    global 
    $uId;
       if(
    $uId == 55){
          return 
    true;
       }
    }
    ?>

  3. #3
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would go with the passing to the function method!

  4. #4
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jahaa
    or you set $uId as global inside the function
    PHP Code:
    <?php
    function Secure(){
    global 
    $uId;
       if(
    $uId == 55){
          return 
    true;
       }
    }
    ?>
    definitely pass the var as a parameter, globals are evil


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •