473,699 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP: passing hidden variables server side

2 New Member
Hi all,

I would like to send a user who lands on page.php to page2.php with some hidden variables (similar to post method).

I assume the header redirect will only pass visible variables (similar to get method).
header("locatio n: http://url.com/page2.php?var1& var2");

Is there a way to automate the redirect and pass along variables picked up from page.php to page2.php that are not visible in the redirected url?

is there a different method or PHP function that can accomplish this? Maybe i can create a form wiht post method and have it submit automatically on the server side?

For various reasons, I can't do this on apache, i need to do this in the PHP code.

thanks in advance,
Jun 26 '06 #1
4 42184
9,065 Recognized Expert Moderator Expert
There are a number of things that you can do, for instance you could

1. Use a Session

Use a session to store the variables you need to pass, in some cases this will add the session id to the url but this is automatic. You have to start the session before and headers are set to the client, i.e. it must be the first thing you do in the script.

2. Use a cookie

Use a cookie to store the variables you want to pass along. Again you must start the cookie before you send and html headers. Of course since the cookie is stored locally an inteligent user may be able to get the data out of it.

3. Just include the page into the current script

If it's a case of the user requests page1.php but you want to return page2.php then you could just include page2.php into page1.php at the relevent point, or if this is not possible create a fragment that can be included into page1.php and page2.php.

4. Use hidden form inputs

I don't think this is a particularly good idea but you could put the data into hidden form input elements and then submit the form using the POST method.

I would probably go with either 1 or 3 personally.
Jun 26 '06 #2
2 New Member
thank you for your reply. i didn't explain myself well enough the first time. I am familiar with all those techniques. i don't think those apply here. let me try to explain the need better:

user lands on page.php?id=123 from another domain where i can't control sessions or cookies.

page.php takes the user and validates some information with a MySQL DB, and then sends the user on to page2.php

page2 may be on another domain or perhaps on the same one as page.php, depending on the results of the process on this page. We need to redirect the user programatically on the server directly to page2.php without the user having to hit a submit button, but we do need to also hide the variable being sent. so i can send them to the next page with header(), but then i can't add the variable info hidden. is there another way to do this?

for lack of better description, i am saying it's like having a post method form that is automatically submitted without the user having to click on the submit button. the #4 option above, can that be done on the server with hidden variables?

thanks again in advance,
Jun 26 '06 #3
1,208 Recognized Expert Top Contributor
you could use sessions like he said or you can do it a more difficult way which i personally wouldn't do but you can... use hidden text fields and use a javascript to submit this form on load.
Jul 17 '06 #4
1,208 Recognized Expert Top Contributor
An example for automaticly posting a form
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function auto() {
  3.   document.myform.submit();
  4. }
  5. </script>
  6. <body onload="auto();">
  7. <form action="page2.php" method="POST" name="myform">
  8. <input type="hidden" value="somevalue" name="you know">
  9. <input type="hidden" value="somevalue" name="what todo here">
  10. <input type="hidden" value="somevalue" name="so do it">
  11. <input type="hidden" value="somevalue" name="ok">
  12. </form>
Jul 17 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: byuedwin | last post by:
Hello, I am starting a new website, and I would like to decide ahead of time what functions (in JavaScript) I will need to write on the server side and which ones on the client side. I believe that some validations are important on the client side, and I am thinking of writing some php validations for the server side. What types of functions are usually written on the server side? What types are usually written on the client side?
by: Mike Fellows | last post by:
Ok, im not sure if this is at all possible and if it is how i go about it is beyond me i have a piece of client side code that requires a piece of data from the server side (an ID number in this case) how can i pass the data from one side to the other, or retrieve it from the webform on the client side? i hope ive explained this properly
by: Skeets | last post by:
i'm passing session and hidden variables between pages. not to mention post values. i'm a little concerned that someone with sufficient knowledge could spoof these vlaues and manipulate the program. is this a valid concern? i'm thinking i can check the submitting page setting up something around the following the following code... $base_name = basename($_SERVER);
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form is correct I need to submit to another page that uses the form data. I first tried making the form submit action= field point to the same file. When the form was correct, I tried loading the next page by using <META http-equiv refresh>. But...
by: Keithb | last post by:
I have some client-side javascript for that I use for dhtml stuff such as hiding div tags based on user menu selections, etc. I need a way to maintain the state of javascript variables across postback. Are there any server side controls that can be used as a container for client-side javascript variables? If not, how do other developers approach this issue? Thanks, Keiht
by: holy moly | last post by:
Hello, the user enters details into a form (values.php) whose action is (insert_values.php), where does the server-side validation code go? (I know other posts on this subject say use PHP_SELF for the action but I don't want to redo all the code) Where should I put the code? I tried it myself but neither way worked so probably the code is wrong for this but I know it works using the PHP_SELF method... if (isset($_POST)) {
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is done in 3 steps: Step 1. Normal http login page. Step 2. A page called login.php that takes the posted username, stores it as $_SESSION, and registers it session_register("username"); user is taken to the personalized page according to his username...
by: Rajeesh123 | last post by:
I have a dom tree(same kind of treeview in .net). when user clicks on it , I pass the id to a hidden field and update it with ajax. The main page has one if clause to get the condition of hidden field and proceed. This if caluse fetches the data from data base and generates path to root of the clicked node. The path is stored on a server side value. I need to use this value to update the value of a text box. No posting can be done as the user...
by: vinot85 | last post by:
Is there is any easy way to do the Server side validation in PHP without using the Server side script? Is there is any options to do the Validations as in .NET by using validation controls? There is a need to validate it by using several if statements in PHP at server side. Give my a finer solution to validate them easily.
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.