473,657 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set attributes into request object in PHP

4 New Member
In java we vll set attributes into request object as request.setAttr ibute(aa,bb), how to do the same in PHP
Feb 24 '10 #1
8 5336
Atli
5,058 Recognized Expert Expert
I suppose:
Expand|Select|Wrap|Line Numbers
  1. // By instantiation 
  2. $request->setAttribute($aa, $bb);
  3.  
  4. // Or statically
  5. request::setAttribute($aa, $bb);
But I have no idea what the "request" object is; whether it is some special Java thing that. I'm just assuming you have a class called "request" and that you want to call the a "setAttribu te" method on it.

If that is not what you are trying to do, elaborate. (And keep in mind that many of us do not know details about the inner workings of Java.)
Feb 24 '10 #2
rythmic
29 New Member
In PHP you have three global arrays to accomplish this.

$_POST, $_GET which contains data sent through post method or get method
There is also $_REQUEST which contains the content found in $_POST + $_GET

to carry data between webpages, use $_SESSION['varname'] = value

To use sessions you also need to use the session_start() ; method at the very beginning of your php file. like this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3.  
  4. $_SESSION['attr_name'] = $value;
  5.  
There can be no print action or even whitespace before the session_start() method
Feb 24 '10 #3
ajay2287
4 New Member
Hi,
In my case i have written a class inside the <?php> tag as below

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. class First{
  4.              public function setValues(){
  5.                  $inputArray=array();
  6.                  $inputArray['1']="one";
  7.                  $inputArray['2']="two";
  8.                  $inputArray['3']="three";
  9.                  //now i have to pass this array to another PHP webpage,such that i 
  10.                  //can print the values of this array in the next PHP page(second.php given below).
  11.              }
  12. }
  13. ?>
second.php
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <?php
  3.  
  4. ?>
  5.      <body>
  6.             //here i have to access the $inputArray and print its value as
  7.             <h1>The value of 1 is:</h1><?php $inputArray["1"] ?>
  8.       </body>
  9. </html>
how to carry the array that is $inputArray from First PHP and print its values in second.php as above.
Feb 25 '10 #4
johny10151981
1,059 Top Contributor
Do you want to pass this array after user action on the web site or you just want to include the file with class into another php file?
Feb 25 '10 #5
Atli
5,058 Recognized Expert Expert
Assuming, again, that at some point in your code the First::setValue function would be called, and that the code in the second page would not be called in the same request, then you would want to use Sessions.

See the examples in the manual for details on how they work. You can also check out this tutorial. (Or one of the many others out there. Come to think of it, I even wrote one of those a few years back xD)
Feb 25 '10 #6
ajay2287
4 New Member
Ya i have to pass the array after user action.
Feb 25 '10 #7
rythmic
29 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. class First{
  4.              public function setValues(){
  5.                  $inputArray=array();
  6.                  $inputArray['1']="one";
  7.                  $inputArray['2']="two";
  8.                  $inputArray['3']="three";
  9.                  //now i have to pass this array to another PHP webpage,such that i 
  10.                  //can print the values of this array in the next PHP page(second.php given below).
  11.  
  12.    // rythmic input!!!: in order to get the array at all you need to return it from the function
  13.     return $input_array;
  14.              }
  15. }
  16. ?>
  17.  
Now, each time that you use this class you will need that page to start with

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start(); // now you are using session vars which are reached through the $_SESSION var which is an array.
  3.  
To store classes in a session you need to serialize the class by using the serialize function built-in in php like so

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3.  
  4. $first = new First();
  5.  
  6. // serialize and add to session
  7. $_SESSION['first'] = serialize($first);
  8.  
Then in second.php you'd write

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3.  
  4. //get the saved class
  5. $first = unserialize($_SESSION['first']);
  6.  
  7. $input_array = $first->setValues();
  8.  
  9. print "<h1>The value of 1 is:</h1>" . $inputArray[1];
  10.  
  11.  
That should do it!

By the way: another thing I noticed, whenever you want to put something in the html code from your php code you need to echo or print it.

So your example with
Expand|Select|Wrap|Line Numbers
  1. // prints The value of 1 is:
  2. <h1>The value of 1 is:</h1><?php $inputArray["1"]?>
  3.  

should be:
Expand|Select|Wrap|Line Numbers
  1. // prints The value of 1 is: 1
  2. <h1>The value of 1 is:</h1><?php print $inputArray["1"];?>
  3.  
best regards
rythmic
Feb 25 '10 #8
ajay2287
4 New Member
Thanks..i used this code, it worked..
Feb 26 '10 #9

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

Similar topics

3
2570
by: Dan Sikorsky | last post by:
How can I get the recordset attributes for a table field in SQL Server 2000 to report the field updatable attribute correctly ... mine keeps saying the fields are not updatable? That is, ( oRecordSet ( oItem ).Attributes & 0x4) is always 0 for every field on SQL Server 2000 Example code: var sSQL = 'SELECT TOP 1 * FROM WHERE ' + sUniqueField + '=' + sUniqueValue + ';';
3
3750
by: Michael Iantosca | last post by:
I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom attribute is attached to the underlying page class. If is attached I want to perform some action. How can I access custom attributes from an HttpModule? I have to pass a target to the System.Attribute.GetCustomAttribute() call to attempt to retrieve the attached attribute. I tried to access...
4
1769
by: jensen bredal | last post by:
Hello, i was not able to find any documentation about the largest value one can assign the "timeout" attribute of the <sessionState section in web.config. any idea?
3
1401
by: Danny Crowell | last post by:
I have a question related to ASP.net sessions and static attributes. In an ASP.net application (MyApp) I have a class called Globals with a public static string called UserName. Will UserName be unique for each session or will the value of UserName be the same for all sessions? For example, John launches MyApp and the UserName is assinged the value "John". Next, Bob launches MyApp and the UserName is assigned the value "Bob". Does John...
6
5991
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to assign a value to them. I wanted to trap for this exception in a subclass using super but it doesn't happen. I have read Guido's tutorial on new style classes and Shalabh's tuturial on new style attributes and methods, and thought I understood...
1
6821
by: LG | last post by:
I want to add attributes to a custom dropdownlist and I found some code on Internet that doesn't work after post back. First time the control has the attributes, but after postback the attributes are lost. It must be a bug in the code bellow. Can anyone help? Thanks, LG using System;
28
1463
by: Alan Isaac | last post by:
I have a class whose instances should only receive attribute assignments for attributes that were created at inititialization. If slots are not appropriate, what is the Pythonic design for this? Thanks, Alan Isaac
1
1147
by: james_027 | last post by:
hi, for example an request object ... is request.user the same as request.__class__.user? THanks james
26
1895
by: tjhnson | last post by:
Hi, With properties, attributes and methods seem very similar. I was wondering what techniques people use to give clues to end users as to which 'things' are methods and which are attributes. With ipython, I use tab completion all the time, but I can rarely tell from the names alone whether it is an attribute or method. Tips? Ideas? Best practices?
11
6238
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as the app is concerned). The problem is, If someone makes a typo, they may get an unexpected error due accidentally calling the original attribute instead of the wrapped version. Does anyone have a simple solution for this?
0
8425
marktang
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...
0
8845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
agi2029
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...
0
5647
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();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
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
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.