Hi guys,

I need to pass a variable from a php page to another php page. There are two methods
GET
POST

both involve user action like submitting by clicking a button or clicking a link

How to send a variable without such user actions?

Recommended Answers

All 6 Replies

Hi guys,

I need to pass a variable from a php page to another php page. There are two methods
GET
POST

both involve user action like submitting by clicking a button or clicking a link

How to send a variable without such user actions?

This is proving to be a very frustrating issue for me and I would be very grateful is somebody with some experience with php could guide me with this.

What is the situation where you wouldn't want some sort of user input? Java/Ajax could do something like that but that's not really my dept. I wouldn't be much help there.

What you could do, but really bad style, is making the document refresh automatically with

<META http-equiv="refresh" content="...">

or JS

document.location.href="..."

If you just want to split up your code, than you can access the output of a php-file with

fopen("http://yourserver/yourfixle.php");

but this may make the whole stuff slow down.

But why do you want to run a script when a user is not viewing your site?

@CFROG and @SDJH

something.php

<? php
....
....
....
$variable1="good morning";
use api to send this variable and retrieve the results
display results in a webpage
controller.js
display second set of results 
?>


ss.php
<? php
....
....
.... 
use the same $variable1 to call another api and retrieve the results
?>

javascript

controller.js

uses ss.php and modifies the results

Does this make any sense?
I want to display results from two types of api's and show it in one page. The situation is a bit more complicated but the thing is that I want to share/send variables between two different php pages.

Is this possible without creating a form and user clicking the button?

I'm not sure what you're after here but it looks like you're already trying to use JavaScript to do this. It can get a bit tricky if you're not familiar with it. To avoid the confusion for you, if at all possible I would just run two separate queries upon page load to display whatever dynamic data you need.

Otherwise you could try something like

<body onload="someJsFunction()">

4 Different ways of passing variables with data between pages

1) Passing variable values between pages using session
2) Passing variables between pages using cookies
3) Passing variables between pages using URL
4) Web Forms

For more:
http://www.plus2net.com/php_tutorial/variables.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.