Passing PHP Session Variables ?

Jan 21, 2009

How to pass (well more like bridge) session information to the client side from server side.

Right now, what I'm basically doing is echoing the userID and the username into a method in JavaScript tag at the bottom of every page.

The reason why I am doing this is simply for AJAX-related interactivity.

This is an example of what the code looks like:

Code:

A) It requires JavaScript code to be pasted within the HTML document (its non-external).

B) It requires the code to be echoed in EVERY PAGE.

C) A PHP Script or Class must maintain the responsibility of printing the session values.

D) The variable data cannot be accessed from any imported javascript files prior to where it was printed.

Now, I'm wondering about using Cookies. This would benefit me since I don't have to inject any ugly javascript code into the HTML output. I can also remove the PHP script that echoes the values and the changes will be purely handled in PHP (cookies can be updated!).

The only issue that's stopping me is simply security. Since cookies can be edited very easily on the client side, then the data can be changed. But then again so can the JavaScript (using a tool like Grease Monkey).

Once again, I am aware to never ever to trust the client side data without any validation; therefore using some sort of hash checksum, the cookie data can be compared to its PHP equivalents.

View 3 Replies


ADVERTISEMENT

Getting Session-variables To PHP

Nov 29, 2009

I'm just beginning with JavaScript (and Ajax). My loginscript now works with Ajax - that is; the script is sending a request to the servers PHP script to check username and password, but I wonder what that script should return - and how to use that response. Either XML or pure text: The response is now "false" if the user couldn't log in for some reason, and the users ID and real name if the login went well...

But then the problem: if login IS ok - so that the users ID and real name is returned from the serverscript - I would like to store those variables in a session variable ($_SESSION in PHP). How do I get those variables back to the client script from JavaScript?

View 4 Replies View Related

Session Variables And Arrays

Jun 28, 2007

I had written code which created a shopping cart into an array using
vbscript and then transferred the information into a session
variable. However what I didn't know was that deleting/manipulating
information in an array using vbscript was not that easy.

In doing some reading and research it seemed that js was more flexible
in this area. My questions:

1) if I want to store cart items/details in an array and session
variable do I need to use only js (and can not switch back and forth
from vbscript and js)

2) if I have an array 6x12 and want to delete all the items
associated with say arrayItem[1, 0...12] what is the proper coding to
delete...is it splice?

3) any good articles about js, arrays, and multidimensional arrays
for a beginner?

View 3 Replies View Related

How To Calculate Average (Mean) Of Session Variables

Aug 2, 2009

My knowledge of programming is very limited. I would like to calculate the average of session variables in Interpreted Java. However, some of session variables may not always be available. The first thing I do is remove the non numerical portion of the session variables:

String [] variables = {"A",'B','C','D','E'};
i = 0;
Iterate through each variable in the array above
while (i < variables.length){
Get the variables to be fixed
value = session.getVariable(variables[i]);
Log the UNFIXED values
session.log("UNFIXED: " + variables[i] + " = " + value);
if(value != null){
Remove non-numerical elements
value = value.replaceAll("\\D", "");
Set variables with new values
dataRecord.put(variables[i], value);
session.setVariable(variables[i], value);
Log the FIXED values
session.log("FIXED " + variables[i] + " = " + session.getVariable(variables[i]));
} i++;
}

Then I make sure the session variables can be treated as numbers:
A = Integer.parseInt(session.getVariable("A")).intValue();
B = Integer.parseInt(session.getVariable("B")).intValue();
C = Integer.parseInt(session.getVariable("C")).intValue();
D = Integer.parseInt(session.getVariable("D")).intValue();
E = Integer.parseInt(session.getVariable("E")).intValue();
Are they still alive?
session.log("A**" + A + "**");
session.log("B**" + B + "**");
session.log("C**" + C + "**");
session.log("D**" + D + "**");
session.log("E**" + E + "**");

I would like to calculate the average of A and B and save it as session variable AB, calculate the average of C and D and save it as session variable CD, and then the average of AB, CD, and E. Here's the weird part; AB, CD, and or E will not always be available. For example, AB will not be available so I need to calculate the average of CD and E or E will not be available so I need to calculate the average of AB and CD. As I said, my knowledge of programming is very limited so if you could provide code snippet with explanation of each step and where to plug in my session variables.

View 1 Replies View Related

JQuery :: Post Checkbox As PHP Session Variables?

Apr 17, 2011

I have a php page (target_market.php), with a form that has 34 checkboxes. I would like the be able to click the boxes and have JS post the 'checked' value to a php session varibale when a button is clicked. If the user navigates away from the page and returns, the pages needs to reload the checkbox session variables.

How do I post the 'checked' value as either YES or NO using JS to another page (target_session.php), so that i can add them to database at a later stage?, but also retrieve the session variables and update the check boxes should the user come back to the target_market.php page?

View 9 Replies View Related

JQuery :: Passing Session Values To The Mother Page?

May 3, 2011

I have a question here, I have a mother page of 2 divs, one for the category list of foods on the left and the right div is a placeholder for the selected food of the category,

Then i have a modal box, which loads the list of foods associated to the category when clicked,

What i wanted to do is, when i select a food from the modal box and click submit, I wanted to populate the selected food into the right div of the mother page, so far the farthest i went is loading the list of food into the modal window,

its like a shopping cart, but instead of redirecting your users to another page, you display all their orders on the same page... can this be achieve, im using jquery+php sessions

View 3 Replies View Related

Passing Variables To PHP

Mar 21, 2005

For some reason, I am using document.referrer in a PHP script that is called as a JavaScript script. The problem is that I need to pass the value of document.referrer to a PHP variable (in the same file) in order to add it to the database. How can I do that?

View 2 Replies View Related

Passing Javascript Variables To JSP

Jul 23, 2005

I need to pass a javascript to JSP code but I cannot figure it out.

View 2 Replies View Related

JQuery :: Passing Variables Into JQ?

Oct 1, 2009

This probably seems pretty trivial to you experts but I just don't know why it doesn't work and would like a nudge in the right direction please.I have a sllide and fade that works great - no problems. I am firing it with a function call from the HTML like so;<a href='#' onClick='sfade('#s1'); return false;>as you see I am passing the div to be faded(and slid) as a variable. Works great. The receiving function is:

var str='';
function sfade(str){
$(str).slideFadeToggle(1000);

[code]....

View 5 Replies View Related

Passing Dynamic PHP Variables?

Jul 16, 2011

I'm creating dynamic buttons and forms for a website and would like the form hidden when it's corresponding button is clicked. However, when I pass button and form name variables to my JavaScript that hides the form, the variables are not being recognised unless I explicitly set them. (e.g 1 and 2 as seen below).

In a nutshell the onlick event doesn't seem to like PHP variables !

[Code]...

View 1 Replies View Related

Passing Variables With OnClick?

Jul 8, 2009

Don't know if this should be under JS or PHP... I have 2 different pages. On the first one, a table shows a list of items. Each has a button that when clicked opens another window with specific size attributes, hence the onClick event. The 2 PHP variables are computed and different for each item (each line).

Here is the line:

<input onClick="javascript:window.open('player_buy.php?send_role=<?=$data['ROLE']?>&send_price=<?=$send_price?>', '_blank', 'status=0,toolbar=0,scrollbars=0,location=no,statusbar=0,menubar=0,resizable=0,width=739,height=320, top=0,left=0')" class="button_sale" type="submit" value="> > >" name="submit">

Now of course, on the popup window, the URL will show .../player_buy.php?send_role=XXX&send_price=XXX

But the goal is to avoid that. So my question is: Is there a way to open such a popup window, pass these variables to it but in a way that it would not show in the URL?

View 6 Replies View Related

Passing Variables To Form?

Jul 8, 2009

I have a javascript function that receives the form name, field name and value and I want to be able to spit that data back to the originating form after doing some processing on the data.

The values are making it to the function perfectly, but when I try to return those values to the form, it tells me it's not a function. I know there's some syntax problem, but I'm just not sure where!

function doThis(one,two,three){
var myFormName = one;
var myFormField = two;
var myFormValue = three;
var goHere = myFormName + '.' + myFormField;

[Code]...

View 4 Replies View Related

Passing Variables In And Out Of Functions

Nov 3, 2010

To formulate the problem simple i have two buttons with the onclick function:

I guess what im asking is how can you set a variable by one onclick function and then use it in any other function?

View 1 Replies View Related

Passing Variables From One Page To Another?

Jun 10, 2011

I want to pass 2 variables from a html page and collecting in another html page using javascript. Say I pass xyz and abc to a page 2.html from 1.html without using cookies. In 1.html page i have many links. each link should be able to pass different variable to 2.html. When some one clicks on a link the variables should be passed to 2.html. I want to know how to collect them and use them.

View 4 Replies View Related

Passing Variables Actively

Apr 4, 2006

I have one page witih PHP where users will be answering a form for file upload. However, I need to give them the option to either upload a file or select one that is already uploaded.

In order for them to select a file that is already uploaded, they will use a pop up window to browse to the file and and select the a file with a radio button or submit button to select the file.

What i need to happen is when they press "select" they window needs to close and that file's url or relative path needs to fill in the "select uploaded file" with the path or url.

I"ll be using PHP in both form and popup for the file, but I cant do that with php without refreshing the page. Can javascript do this and how would I go about this.

View 2 Replies View Related

Javascript Passing Variables To App

Jul 16, 2006

A while back I was working on learning C++. However after finding out that making API's was too difficult I switched over to HTML and Javascript for a while to get it to do what I want without having to fry my brain on weird code statements.

Well now I've reached the barrier of being able to save data. For a while I've just had it to the point where the code I need is saved in a textarea and I copy and paste it in notepad. Then upon reentering I pull it out of Notepad and paste into the testarea.

Well enough with the bla bla bla. Is there a way I can use the <form method="post"> stuff to pass a variable to a C++ compiled program?

All I need to know is: 1) can I use <form method="post" action="SomeProg.exe"> and 2) what would the name of the posted variable be to use in my C++ code? As you can tell I running client-side so PHP and other server-side languages that WinXP don't support without special installation wont work.

View 2 Replies View Related

Passing PHP Variables Not Working ?

Aug 11, 2010

I've been workling seperately with PHP/ MySQL and am now trying to get things together with jQuery which I have so far only used with non-dynamic content. Here is the setting I am trying to achieve:

I have one php file that generates two different contents depending on the setting of a status-variable $ncs. If $nsc=0 the main page is loaded, showing an overview of all available news-articles. If $ncs=1 the content of a specific article is shown fully. The jQuery connected to each case differs. So i would like to pass the varible $ncs over to my jQuery script:

Code JavaScript:

I have checked that $ncs is not NULL on the rendered page. However after being passed to the jQuery script the variable is undefined. I have never connected PHP and jQuery so it is probably a general twist in my idea of how it works. I tried passing different variables and all are undefined in jQuery. What do I have to attend to when passing PHP-variables to jQuery?

View 3 Replies View Related

Passing Multiple Variables Via Url

Sep 12, 2003

I'm trying to pass multiple variables using a url on a Java function call.
the code I have that passes the 1 variable is:

function HandleChange() {
parent.CustomerIf.document.location.href="CustomerReturn.asp?id=" + varName.options[varName.selectedIndex].text;
}

which passes the chosen data (being loaded from a database) from a drop down box on an onchange event in asp script.

What I want to do is pass multiple variable via the above url script that the next page will get by the request.querystring method.

something like this:

function HandleChange() {
parent.CustomerIf.document.location.href="CustomerReturn.asp?id=" + varName.options[varName.selectedIndex].text + "address=" varAddress.value;
}

View 4 Replies View Related

Passing Variables Between Web Pages

Jan 19, 2004

I am attempting to display info put into an array from an onClick() event in a different page - I have created different functions which populate an array with different info dependant on which link the visitor clicks ie HTML Code:

<a href="nextpage.htm" onClick="functiontopopulatearray()"> SELECT</a>

The function seems to work fine, however when the next page loads and I attempt to access the array elements they are now undefined - both pages are linked to the same JS document.

View 2 Replies View Related

Passing Variables Between Two Windows

May 24, 2004

Basically, I have a window with an empty text field in. When I click on a link, another window appears on top of the first. (A pop up window.)

The popup window also has a text field in it. If I type "Test" in the popup window's text field and click "Submit", is there a way I can send that value to the empty text field in the first window?

View 2 Replies View Related

Passing Variables From One Window To Another

Apr 18, 2005

We have a content management system that requires us to fill in 20 fields for metadata about a page. We store the metadata in a separate database for our records.

I'd like to be able to open a window with the data from our database, click a link, and have it fill in the form in the content management system (hosted by a different organization, so window.opener is out of the equation).

I tried this

<a href="#" onClick="window.open('http://www.google.com', 'Google'); window.Google.f.q.text.value='my name'">Enter my name in Google!</a>

In this example, I'd click a link that would open up Google, then pass the value "my name" to Google's search bar. Unfortunately for me, it didn't work.

Am I asking too much? I'd hate to have to rekey or copy/paste 20 fields worth of metadata each time I create a page.

View 6 Replies View Related

Passing Variables To Php Thru $_post??

Mar 18, 2007

At the moment I have this function, which passes variables to a php file with $_get

function savePath() {
//store title
pathTitle = 'pathTitle=' + document.getElementById("pathTitle").value;
//pathLength = getPathLength();
window.location.href = "save-path2.php?"+pathTitle;
}

but I need to use $_post

function savePath() {
//store title so we can use $_post
pathTitle = 'pathTitle=' + document.getElementById("pathTitle").value;

data = '<form action="save-path2.php" name="formData" method="post">
<input type="hidden" name="pathTitle" value="'+pathTitle+'" />
</form>'
document.formData.submit();
}

How would i automaticly submit the form?

View 1 Replies View Related

Passing/processing URL Variables

Aug 21, 2000

I forget how to parse the variables passed on the URL like this:

<A HREF="http://www.mysite.com?bla="blahhh"" TARGET=_blank>http://www.mysite.com?bla="blahhh"</A>

How would I check this for a value and add some code to a page if it is equal to this value?

View 2 Replies View Related

Jquery :: Passing Variables From Php?

Nov 21, 2010

Im simply trying to make a dynamic searchbar so that the results pop up as someone write in the keywords. Problem 1 :When i pass foreign char types through jquery's $.ajax(); such as:

[code]....

they get translated to some weird characters when i try to compare them in the mysql database.javascript side:

Code:

$("#id_study4").keyup(function() {
var keyword = $("input[name=study4]").val();
var school_id = $("select[name=school4]").val();

[code]....

And the second problem is simply when i get he search results, i have the keyword emphasized with bold font weight, and text underline so that people can see. The problem here is that if i search with the keyword bach, then result becomes <b>bach</b>elor with all small letters when it should be <b>Bach<b/>elor. The way i have done this can be seen below:

Code:

str_ireplace($keyword, "<b>".$keyword."</b>", $study['study_name'])

View 2 Replies View Related

Passing Variables From One Object To Another

Feb 6, 2011

I have implemented an Ajax object - a div containing another ASP file which can be updated dynamically. This ASP page has a number of checkboxes. Is it possible to use JS (or any other tool) to check the checkbox status (i.e. like javascript's if (field.checked)

[Code]....

But now the form is in the Ajax object's ASP file, so "document" wouldn't work.

View 4 Replies View Related

Clarification On Passing Variables

Dec 10, 2011

clarification on passing variables

[Code]...

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved