Hi,
I normally program in perl and am trying to translate one of my scripts to php.
The following snippet doesn't set the variable and I thought it would!
What the script does is to redirect to a different script depending on whether a query exists, and depending on the existence of a parameter if there is a query string.
I would like to know why, when calling without a query $scriptrl is not being set, and also how do I query a parameter from a GET call (equivalent of CGIThanks,Code:$var = param('variable');
Jon
Code:$query = $_SERVER["QUERY_STRING"]; if(! isset($query)) { $scriptrl = 'g_search.php'; }
Last edited by jonnyfolk; 03-03-2010 at 02:17 PM. Reason: changed script name for privacy reasons - no impact on thread!
EDIT: nvm.
Try:
or to check if it's empty:Code:if(!isset($_SERVER['QUERY_STRING']))
Not sure if this is what you mean?Code:if(empty($_SERVER['QUERY_STRING']))
As your script's if loop will always return true as before the loop you set the variable $query ( and the function isset is independent of whether a variable is empty or not, just cecks if it's set - it's set ).
I see - I hadn't realised that consequence. I chose the 'empty' option and it worked perfectly. Thanks.
Regarding the param from the GET call, eg script.php?var=one&var1=two&var2=three how to I get the var1 value?
isset and empty is a little special and can not always be trusted, as some can be true even if they have the value 0 (zero). The safest way is actually to check with if ($var == "").
you get the var1 with $_GET['var1']
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
Glad to hear that it's working now
@Orjan True, thanks for heading that up, I experienced that problem with the value '0' a while ago indeed, forgot about that but I think that was with isset function.
Not sure if this would be a problem in this case though.
And the GET var1 can indeed be accesed within the GET array with as sub-variable name 'var1', as in general it's:
So when adding a variable through url called 'var1' it automaticly is converted into a GET variable $_GET['var1'].Code:$_GET['sub_variable_name']
Cheers.
Thank you for your input. I appreciate the responses and will consider the information I've been given. A very interesting (and successful) first day on the boards!!
Jon
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks