Jump to content

Using variable info into other page.


smartguyin

Recommended Posts

I have set a variable as below

$title = "My Product Title"

I have created this variable in index.php and i wanted to use it in product.php how can i transfer from index.php to product.php soo that i can directly use it in all the product pages... like in title tag <title>[title]</title>

Please give me your suggestions.

Thanks in Advance
Link to comment
Share on other sites

You could do it using sessions but if the variable is set in index.php they would have to have been on index.php for it to work on the other pages.

I think the best way would be to set it in an external file then calling that file on the pages you want the variable to be used on.

e.g. the code in the file would be
[code]
$title = "This is the title";
[/code]

and the code you would use to call it would be (assuming the file was called title.inc)
[code]
include("title.inc");
[/code]

hope that helps
Link to comment
Share on other sites

No in the above example you showed me to prepare a separate file title.inc NO i don't want to use this.
[b]
I want the index.php send the variable directly to product.php soo that the variable content in index.php and used in product.php directly.[/b]
Link to comment
Share on other sites

How are your users getting from index.php to product.php?

A form? A link?

You can always uses sessions. In index.php
[code]<?php
session_start();
$some_variable = "Testing 123";
$_SESSION['some_variable'] = $some_variable;
?>[/code]
In product.php:
[code]<?php
session_start();
$some_varible=$_SESSION['some_variable'];
?>[/code]

Ken
Link to comment
Share on other sites

I'll give another example too get it more simplify.

Suppose there are 2 files product.php and header.php

header.php contains the meta tag and heading html code which is most common in all the product pages.

product.php contains the other part with all the content. >> There is a heading used in this page using this $product

Now I want to use the $product info in my header.php in title tag soo that the heading can be displayed in title tag.

I Hope the things must be clear now..

Thanks in Advance !
Link to comment
Share on other sites

  • 7 months later...
[quote author=kenrbnsn link=topic=87296.msg351524#msg351524 date=1141445981]
How are your users getting from index.php to product.php?
A form? A link?
You can always uses sessions. In index.php
[code]<?php
session_start();
$some_variable = "Testing 123";
$_SESSION['some_variable'] = $some_variable;
?>[/code]
In product.php:
[code]<?php
session_start();
$some_varible=$_SESSION['some_variable'];
?>[/code]
Ken
[/quote]


New here but desperately going through old files.  I probably should post here as i had put this somewhere else but this is relevant to my quest so I hope I am forgiven.

I am tying to modify some files that have the following simplified structure
[code]
<?php
include 'a.inc';
include 'b.inc';
?>

a.inc has the following struture
<?php
"A form for user input"
include 'A1.inc';
include 'A2.inc';
?>

A1.inc has the following struture
<?php
function 1 {
$x = "Value from user input form"
}
?>

A2.inc has the following struture
<?php
function 2 {
$y = $x + 1
}
include 'A2_1.inc';
?>

A2_1.inc has the following struture
<table>
<tr>
<td>"The value of $y"</td>
</tr>
</table>
[/code]

The files are a bit more complicated than this (Gallery2 photo display software) but this is the basic structure.  I am struggling to get "The value of $y". 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.