?
Solved

window.location.search in php?!?

Posted on 2003-03-24
5
Medium Priority
?
309 Views
Last Modified: 2013-12-12
Hi,

how can I get the variable after the ? in the address line? (phptest.php?variable) In javascript it's window.location.search. But how is it called in php? Or is this not possible in php, because php is server based???

thanks
0
Comment
Question by:Bohne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8194255
Try ...

$_SERVER['QUERY_STRING'];

For a complete list of available variables, try ...

<?php phpinfo(); ?>

Richard.
0
 
LVL 3

Expert Comment

by:jayrod
ID: 8194539
Then you can use the parse() function to get all of the variables in the format of:

?variable=something?variable2=otherthing
0
 
LVL 8

Accepted Solution

by:
alakriti earned 60 total points
ID: 8199381
when there are things in the Query String like this

page.php?var=value&var2=something

all u need to do to grab the contents of them would be to use $_GET['var'] and $_GET['var2'] if you are using an older version of PHP it would be $HTTP_GET_VARS['var'] and $HTTP_GET_VARS['var2']

hope this helps. :)
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8201590
Alakriti.

That is absolutely right for name/value pairs.

But it doesn't work for ...

www.site.com/page.php?var1&var2&var3

Richard.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8201751
Oops. I'm wrong.

The variables ARE processed into $_GET / $HTTP_GET_VARS, but without values!

So,

print_r($_GET);

returns

Array
 (
 "var1" =>
 "var2" =>
 )

You would be able to use ...

foreach($_GET as $key => $value)
 {
 echo "The variable '$key' was supplied with the value '$value'.\n";
 }

to get to each variable sent.

Richard.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question