Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-30-2012, 01:24 AM   PM User | #1
wuzhannanan
New Coder

 
Join Date: Jul 2009
Location: Chicago, IL
Posts: 54
Thanks: 5
Thanked 0 Times in 0 Posts
wuzhannanan is an unknown quantity at this point
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?
wuzhannanan is offline   Reply With Quote
Old 04-30-2012, 01:58 AM   PM User | #2
Sailab
New to the CF scene

 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Sailab is an unknown quantity at this point
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 01:25 PM.. Reason: signatures only allowed through the control panel
Sailab is offline   Reply With Quote
Old 04-30-2012, 02:04 AM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,511
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Old 04-30-2012, 05:42 AM   PM User | #4
wuzhannanan
New Coder

 
Join Date: Jul 2009
Location: Chicago, IL
Posts: 54
Thanks: 5
Thanked 0 Times in 0 Posts
wuzhannanan is an unknown quantity at this point
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.
wuzhannanan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:20 PM.


Advertisement
Log in to turn off these ads.