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
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Unhappy How do you do this in PHP?

    I'm familiar with classic ASP. In ASP, I can announce a variable like this:
    Code:
    <% dim pageTitle %>
    And save this in a separate .asp file. Then, on another page, I can include that .asp file and write ASP code like this:
    Code:
    <% pageTitle = "Furniture" %>
    Which assigns pageTitle a value. With that assigned, I can write an if statement like this (on another, separate page):
    Code:
    <% if pageTitle = "Furniture" then %>
    <script type="text/javascript" src="/skins/hp.load.js"></script>
    <% end if %>
    Now I've been looking online for how to do this same exact process in PHP, but I'm not having luck. It's important that all of this function in separate files. So the dim happens in one include, the value is assigned in another include file, and the if statement happens in a third file.

    Can anyone help?

  • #2
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your question isn't clear enough. What exactly you like to do? If you mean how to get a variable which you already stored somewhere then use globle keyword to share your variable across whole application. In the same page you can also use defined keyword to define a variable.
    Last edited by vinyl-junkie; 04-30-2012 at 02:25 PM. Reason: signatures only allowed through the control panel

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by wuzhannanan View Post
    I'm familiar with classic ASP. In ASP, I can announce a variable like this:
    Code:
    <% dim pageTitle %>
    In php you don't need to declare variables.

    Quote Originally Posted by wuzhannanan View Post
    And save this in a separate .asp file. Then, on another page, I can include that .asp file and write ASP code like this:
    Code:
    <% pageTitle = "Furniture" %>
    PHP Code:
    <?php
    $pageTitle 
    'Furniture';
    ?>
    Quote Originally Posted by wuzhannanan View Post
    Which assigns pageTitle a value. With that assigned, I can write an if statement like this (on another, separate page):
    Code:
    <% if pageTitle = "Furniture" then %>
    <script type="text/javascript" src="/skins/hp.load.js"></script>
    <% end if %>
    PHP Code:
    <?php
    if ($pageTitle == 'Furniture')
       {
    ?>
       <!--Your thing here-->
    <?php
       
    }
    ?>
       }
    Since you don't need to declare variables in php until you use them, I've no idea how this affects any included files in your project.
    I can't really think of anything to write here now...

  • #4
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Sailab View Post
    Your question isn't clear enough. What exactly you like to do? If you mean how to get a variable which you already stored somewhere then use globle keyword to share your variable across whole application. In the same page you can also use defined keyword to define a variable.

    Ask me more if you like
    Ok, maybe to be clear, here's what I want to do:

    On my Furniture pages, I have a bunch of CSS and JS that I don't want loaded on other pages. Only these Furniture pages. I thought this would be the best way to do this, because the <head> section of my code is in one include file that's used by all pages on my site.


  •  

    Posting Permissions

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