how to pass variable from one page to another

Started on the old forum in October 2012 · view the original in the archive · old links redirect here

15 replies · 864 views · started 14 years ago · 1 min read

7 participants
razor Developer · 52 posts #1

how to pass variable from one page to another page without the use of form or url. e.g: i have a variable

$referer= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

in get.php file and i need to pass the $referer value to click.php , then how to do it?

subzero Super moderator Fellow · 3,954 posts #2

Var1 change to what variables you need

$variable_page1 = $_GET['var1'];

Clean your var

isset($_GET['var'])?$var=mysql_escape_string($_GET['var']):$var='SomeDefaualtValue';

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

razor Developer · 52 posts #3

subzero wrote: Var1 change to what variables you need

$variable_page1 = $_GET['var1'];

Clean your var

isset($_GET['var'])?$var=mysql_escape_string($_GET['var']):$var='SomeDefaualtValue';

thank you for quick reply but i am unable and this is not what i asked,

as per i said like i am getting the referer in get.php but i need to insert that value in DB from click.php when i am getting a real click after checking this, so need to pass the $referer without any form or using url to get function....

subzero Super moderator Fellow · 3,954 posts #4

Other words,

You want to pick up more then 1 file

file1 file2

both submit same values ?

if you trying to by pass a click to a toplist or any type from other server with out clicking does not work..

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

jaidon20k Developer · 64 posts #5

Lol use header("location: link-to-go.php");

Edyka Junior · 11 posts #6

there are many ways 🙂 it depends on how you get from page one to page two. Via link? or do you use redirection? ... the best way would be with sessions 🙂 or cookies.... or you can make it a lot easier and move the code from click.php to get.php 🙂 as I said... it depends...

or you can use the POST method... via a form and a button 🙂

razor Developer · 52 posts #7

jaidon20k wrote: Lol use header("location: link-to-go.php");

lol did u read what i wanted to know?

Ghost Senior · 366 posts #8

i would make a form. that was made to LOOK like a link. then use the input hidden to pass the data from 1 page to another.

css to make form/button look like link

.button-link
{
      background: none;
      border: 0;
      color: #65ACCA; /** #87CEEB */
      text-decoration: none;
      font-size: 100%;
}
.button-link:hover
{
      background: none;
      border: 0;
      color: #65ACCA; /** #87CEEB */
      font-weight: normal;
      font-size: 100%;
}
.button-link:visited
{
color: #800080; /** Purple */
text-decoration: none;
}
.button-link:active
{
color: #FF0000; /** Red */
text-decoration: none;
}

then the form

echo '<form action="TO-PHP-FILE.php" method="post">';
echo '<input type="hidden" name="referer" value="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'"/>';
echo '<input class="button-link" type="submit" name="submit" value="Lets Submit The Data"/>';
echo '</form>';

Then On File To Recieve Data.

if(!empty($_POST['submit']))
{
$referer = $_POST['referer'];
}

i use this method to make my buttons looks like links. then pass/create the new data.

hmm. poop. i guess i didnt read properly. you dont want to use a form. whats wrong with using the include(); function to include the file with the data to the file in question?

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
razor Developer · 52 posts #9

Ghost wrote: i would make a form. that was made to LOOK like a link. then use the input hidden to pass the data from 1 page to another.

css to make form/button look like link

.button-link
{
      background: none;
      border: 0;
      color: #65ACCA; /** #87CEEB */
      text-decoration: none;
      font-size: 100%;
}
.button-link:hover
{
      background: none;
      border: 0;
      color: #65ACCA; /** #87CEEB */
      font-weight: normal;
      font-size: 100%;
}
.button-link:visited
{
color: #800080; /** Purple */
text-decoration: none;
}
.button-link:active
{
color: #FF0000; /** Red */
text-decoration: none;
}

then the form

echo '<form action="TO-PHP-FILE.php" method="post">';
echo '<input type="hidden" name="referer" value="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'"/>';
echo '<input class="button-link" type="submit" name="submit" value="Lets Submit The Data"/>';
echo '</form>';

Then On File To Recieve Data.

if(!empty($_POST['submit']))
{
$referer = $_POST['referer'];
}

i use this method to make my buttons looks like links. then pass/create the new data.

hmm. poop. i guess i didnt read properly. you dont want to use a form. whats wrong with using the include(); function to include the file with the data to the file in question?

ghost sir your idea is very good and i also think it ago but i cannot do that as it is a advertisement system and publishers will request the page get.php from their site with our ad code so this thing can not be set there, anyway thanks for suggession

arnage Lead · 811 posts #10

razor wrote: how to pass variable from one page to another page without the use of form or url. e.g: i have a variable

$referer= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

in get.php file and i need to pass the $referer value to click.php , then how to do it?

It would be much better if you post the code... Anyway you can define constant var or if it is in function in click.php define $referer global:

function something() {
global $referer;
// The rest of code...
}

Or just make it $GLOBALS['referer'] and use it where you want.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Ghost Senior · 366 posts #11

arnage wrote: It would be much better if you post the code... Anyway you can define constant var or if it is in function in click.php define $referer global:

function something() {
global $referer;
// The rest of code...
}

this would of been my next suggestion. just make it a function. global $referer; that would do it.

was expecting a reason for the include function to not be used. but i guess there wasnt one lol.

p.s sorry for late replying. had to go shops etc. needed to get me my smokes for the night.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
softwarefreak Senior · 349 posts #12

If you dont want the world to change that value of the variable while transporting, then

//ads.php
session_start();
$_SESSION['ref'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
//Do something
//click.php
session_start();

$ref = $_SESSION['ref'] // value was set in ads.php
//Do something
session_destroy();

NOTE that, session still needs cookies to be enabled in end user's browser, else you need to pass the constant SID in URL

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

subzero Super moderator Fellow · 3,954 posts #13

To use the @import rule, type:

 <style type="text/css">
   @import url("import1.css");
   @import url "import2.css";
 </style> 

The url() is not required. The double quotes are required for valid XHTML, but browsers that support url() tend to support it with or without quotes.

You can also include an @import rule in a style sheet with styles:

 <style type="text/css">
   @import url("import3.css");
   p { color : #f00; }
 </style>

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

arnage Lead · 811 posts #14

softwarefreak wrote: If you dont want the world to change that value of the variable while transporting, then

//ads.php
session_start();
$_SESSION['ref'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
//Do something
//click.php
session_start();

$ref = $_SESSION['ref'] // value was set in ads.php
//Do something
session_destroy();

NOTE that, session still needs cookies to be enabled in end user's browser, else you need to pass the constant SID in URL

World can't change it if its handeled properly. 🙂 And using sessions in this type of script where many people constantly clicks for such a small thing increases a risk of overhead.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
softwarefreak Senior · 349 posts #15

arnage wrote: World can't change it if its handeled properly. 🙂 And using sessions in this type of script where many people constantly clicks for such a small thing increases a risk of overhead.

Bro, if get, post, cookies are used, the value can be changed easily by an advanced end user. safe side is session only. but if an algorithm is used to encode the data instead of just base64 encoding/decoding, thats ok I guess 🤝

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

arnage Lead · 811 posts #16

But i didn't mention get, post or cookies anywhere, i'm just saying that using session in this case is bad idea. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close