Printable Version | Subscribe | Add to Favourites
New Topic New Poll New Reply
Author: Subject: OT... PHP programers
tegwin

posted on 4/12/09 at 01:13 PM Reply With Quote
OT... PHP programers

Do we have any PHP programers in the house? I have a bit of an issue reading some variables from a server array... and im confused!







------------------------------------------------------------------------------------------------------------------------
Would the last person who leaves the country please switch off the lights and close the door!

www.verticalhorizonsmedia.tv

View User's Profile Visit User's Homepage View All Posts By User U2U Member
sprouts-car

posted on 4/12/09 at 01:49 PM Reply With Quote
I've done some php, whats the problem?

Chris

View User's Profile Visit User's Homepage View All Posts By User U2U Member
tegwin

posted on 4/12/09 at 02:01 PM Reply With Quote
Basically...

if I look at the URL it looks like this:
quote:

http://webappdomainname/index.phtml?d=136435&preview=1&t=1259923523



However, if I run this code to show all variables
quote:

# <?php # print '<pre>' . htmlspecialchars(print_r(get_defined_vars(), true)) . '</pre>'; # ?>



I get this:
quote:

[QUERY_STRING] => domain=ZnZlcg%3D%3D&company_id=79&contact_id=7226&selected_contact_id=&document_id=136435&document_stack=a:1:{i:0;i:136435;}&u ser_var_page_name=get+defined+variable&user_var_page_description=&user_var_page_published_date=4th+December+2009&user_var_page_modified_da te=4th+December+2009&user_var_page_created_by=john+smith&user_var_page_modified_by=john+smith&user_var_custom_icon=&frame_id=244892




I need to get the "contact_id" value from that _server query string and use it in my program.... but I cant for the life of me figure out how to get it..

The normal method of
quote:

1. <?php 2. 3. echo $_get['contact_id']; 4. 5. ?>



Does not work, because the "contact_id" is not actually in the URL for the $_get to look at....

Any ideas how I can get that variable from the query string rather than from the URL string?

[Edited on 4/12/09 by tegwin]





------------------------------------------------------------------------------------------------------------------------
Would the last person who leaves the country please switch off the lights and close the door!

www.verticalhorizonsmedia.tv

View User's Profile Visit User's Homepage View All Posts By User U2U Member
sprouts-car

posted on 4/12/09 at 02:27 PM Reply With Quote
Could it be in the session variables?

ie SESSION['contact_id']

Failing that, i found this example which should help (with a little mod):

quote:
After a fruitless attempt find a built-in function whic did this, I wrote this functions to find out all the variables (well, those I wanted) in current scope and their values. I believe this is going to be handy in debugging.

<?php
/**
* @desc works out the variables in the current scope(from where function was called).
* Returns an array with variable name as key and vaiable value as value
* @param $varList: variables returned by get_defined_vars() in desired scope.
* $excludeList: variables to be excluded from the list.
* @return array
*/
function getDefinedVars($varList, $excludeList)
{
$temp1 = array_values(array_diff(array_keys($varList), $excludeList));
$temp2 = array();
while (list($key, $value) = each($temp1)) {
global $$value;
$temp2[$value] = $$value;
}
return $temp2;
}

/**
* @desc holds the variable that are to be excluded from the list.
* Add or drop new elements as per your preference.
* @var array
*/
$excludeList = array('GLOBALS', '_FILES', '_COOKIE', '_POST', '_GET', 'excludeList';

//some dummy variables; add your own or include a file.
$firstName = 'kailash';
$lastName = 'Badu';
$test = array('Pratistha', 'sanu', 'fuchhi';

//get all variables defined in current scope
$varList = get_defined_vars();

//Time to call the function
print "<pre>";
print_r(getDefinedVars($varList, $excludeList));
print "</pre>";
?>

View User's Profile Visit User's Homepage View All Posts By User U2U Member
tegwin

posted on 4/12/09 at 03:37 PM Reply With Quote
I tried that bit of code from the PHP manual... thats what gives me the massive list of variables...

Session doesnt work





------------------------------------------------------------------------------------------------------------------------
Would the last person who leaves the country please switch off the lights and close the door!

www.verticalhorizonsmedia.tv

View User's Profile Visit User's Homepage View All Posts By User U2U Member
TimEllershaw

posted on 4/12/09 at 03:44 PM Reply With Quote
Can you stick the long Query String through the parse_str() function to get it ?


I'll have a think about it when I get a spare minute.

Cheers,

Tim.

View User's Profile E-Mail User Visit User's Homepage View All Posts By User U2U Member
tegwin

posted on 4/12/09 at 03:51 PM Reply With Quote
http://www.php.net/manual/en/function.parse-str.php

That might explain a few things...

But im not sure what exactly to try... appreciate any thoughts





------------------------------------------------------------------------------------------------------------------------
Would the last person who leaves the country please switch off the lights and close the door!

www.verticalhorizonsmedia.tv

View User's Profile Visit User's Homepage View All Posts By User U2U Member
TimEllershaw

posted on 4/12/09 at 04:40 PM Reply With Quote
I would have expected all the arguments to be in the $argv array, but know there is some issue with having to set something in the php.ini.

if you do this what do you get :

foreach($_SERVER['argv'] as $k=>$v)
echo "$k -> $v \n";

[Edited on 4/12/2009 by TimEllershaw]

View User's Profile E-Mail User Visit User's Homepage View All Posts By User U2U Member
Gav

posted on 4/12/09 at 04:47 PM Reply With Quote
If its a posted form you need to use $_POST["Contract_Id"]






View User's Profile Visit User's Homepage View All Posts By User U2U Member
tegwin

posted on 4/12/09 at 07:43 PM Reply With Quote
quote:
Originally posted by TimEllershaw
I would have expected all the arguments to be in the $argv array, but know there is some issue with having to set something in the php.ini.

if you do this what do you get :

foreach($_SERVER['argv'] as $k=>$v)
echo "$k -> $v n";

[Edited on 4/12/2009 by TimEllershaw]



That gives me all of the query string variables....





------------------------------------------------------------------------------------------------------------------------
Would the last person who leaves the country please switch off the lights and close the door!

www.verticalhorizonsmedia.tv

View User's Profile Visit User's Homepage View All Posts By User U2U Member

New Topic New Poll New Reply


go to top






Website design and SEO by Studio Montage

All content © 2001-16 LocostBuilders. Reproduction prohibited
Opinions expressed in public posts are those of the author and do not necessarily represent
the views of other users or any member of the LocostBuilders team.
Running XMB 1.8 Partagium [© 2002 XMB Group] on Apache under CentOS Linux
Founded, built and operated by ChrisW.