Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts

    Passing Variable And Scope

    I have a variable at the start of my page that gets the value from the URL, looks up the database of that value and assigns a title to it in $title. So for each page I have a separate title assigned to it.

    I have a function that counts the number of people browsing my web page (that I found here) that has a nice little script that does this. However, I would like to add to it that value from $title so that it also adds the page they are currently viewing into the database too.

    Is this possible and am I going about it the right way? I've tried various ways of doing this, but I can't get the value from $title to $counter and into that database.
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    You will need to do this:

    PHP Code:

    $title 
    whatever;  //declared in global scope.

    function foo()
    {
      global 
    $title;  //brings the globally declared variable into local scope.

      //Now use $title as you wish - note that any changes you make to $title here will be reflected globally.

    Last edited by mlse; 01-08-2008 at 02:41 PM.

  • #3
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Just managed to work that out thank you
    Also had another problem that i.p's weren't always being stored but that was just a conflict with two people having the same I.P. Thanks for your help!
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    global $title;
    Do not use global unless completely necessary. Which in this case it isn't. Global is a bad shortcut.

    It's bad design for a function to depend on external situations. A function should be completely separated.

    I'm not sure I understand the question though so I don't know how else I would do it.


  •  

    Posting Permissions

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