CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 How do I know if parameter exists

Print topic Send  topic

Author Message
Gena

Posts: 591
Posted: 06/03/2008, 11:14 AM

How do I know if parameter exists? I mean, I have some url, it can be with / without parameter.

...mypage.php?param=1
...mypage.php

So I need to know if url consists "param" itself (not value ;-) )
_________________
Gena
View profile  Send private message
datadoit
Posted: 06/03/2008, 11:34 AM

Gena wrote:
> How do I know if parameter exists? I mean, I have some url, it can be with /
> without parameter.
>
> ..mypage.php?param=1
> ..mypage.php
>
> So I need to know if url consists "param" itself (not value ;-) )
> _________________
> Gena
> ---------------------------------------

Try this:

$query = CCGetQueryString("QueryString","");
$found = strpos(strtoupper($query),strtoupper("param"));
if ($found) {
echo "Hey! I see it!";
}
else {
echo "Nope. Not found.";
}
Gena

Posts: 591
Posted: 06/03/2008, 12:03 PM

datadoit,

nice idea! thanks! will give it a try!

_________________
Gena
View profile  Send private message
Manuel A. Martinez
Posted: 06/04/2008, 9:00 PM

HI;

You should use the functions provided to you by CSS4.

1. CCGetFromGet(ParameterName, DefaultValue)

or

2. CCGetFromPost(ParameterName, DefaultValue)

e.g.

$value = CCGetFromGet("param",0);
if ($value == 0){
echo "Param Does not exist";
}
else {
echo "Param Exists, and the value is " . $value ;
}
Gena

Posts: 591
Posted: 06/04/2008, 10:45 PM

Hi Manuel,
thank you for your replay, but it is not what I need. If you read my first post, I need to know if url consists "param" itself (not value ;) ) but CCGetFromGet or CCGetParam returns Value but not parameter itself.

_________________
Gena
View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/05/2008, 3:29 PM

Hi Gina

Try This

Let me know if it works for you.

function selfURL() {
$s = empty($_SERVER["HTTPS"]) ? ''
: ($_SERVER["HTTPS"] == "on") ? "s"
: "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
: (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2));
}
$URL=selfURL();echo $URL;
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
Gena

Posts: 591
Posted: 06/05/2008, 3:44 PM

hi John,

my name is Gena (not Gina :-D )

thank for your code. but where is checking for Parameter name there?

_________________
Gena
View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/05/2008, 4:11 PM

Sorry Gena

The code I sent for you retrieves the entire URL including parmeters into a string

eg: $URL=selfURL();

now you have the complete URL in a string and can do anthing with it. Try echoing the string $URL, I'm sure that will help you.

If you know the name of the parameter just search the string

if(strpos($URL,"param"){DO HERE IT IS:} (Note probably good to use strtoupper like shown above)

If you do not know the names of the parameters you can scan thru the string

parsing between the ? and = chars or the & and = chars and you will get all the parameter names.

Sorry I thought there were plenty of string checking examples alredy posted here only the issue of getting the parameter names was missing.

Does that help?

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
Gena

Posts: 591
Posted: 06/05/2008, 5:14 PM

John, thank you. This is also good idea.

but don't you think that using of CCGetQueryString is much more easy? and this is build-in function too.
_________________
Gena
View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/06/2008, 7:46 AM

My dear Gena

I my experience there are always more than one way to do anything in code. It all depends on what you are trying to do.

CCGetQueryString Certainly might work just fine in your application. I do not know. If you think it fills your needs then by all means it is better.

Take Care
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.