Solved

how to get URL variable

Posted on 2003-11-01
7
250 Views
Last Modified: 2006-11-17
i have a problem. i am declaring one variable id  in one site and want to retrive  that id in another site. how can i?
like http://localhost/New%20Site/jeans.php?=1

i want one(1) after the ?= sign.

how to get this variable 1?
0
Comment
Question by:sachinamanath
7 Comments
 
LVL 6

Accepted Solution

by:
aolXFT earned 20 total points
ID: 9662823
I think you need to make yourself slightly clearer in the question.

If you are doing what I think you are trying to do, and just pass arguments you can call the site like

http://localhost/newjeans/site.php?id=1

Then on the other site you can do something like

<?php

$id = $_GET['id'];

?>
0
 

Expert Comment

by:keewooi
ID: 9664936
use $_SERVER['QUERY_STRING'];

eg:

<?

    echo $_SERVER['QUERY_STRING'];

?>
0
 
LVL 2

Expert Comment

by:HeadAcheMike
ID: 9666442
heres a full example of how to pass a variable from one page to the next, it should help you understand how it works better:

file 1 (1.php in example)

<?php
$var = 5;
echo "<a href=\"2.php?variable=$var\">link</a>";
?>

file 2 (2.php in example)

<?php
$newvar = $_GET['variable'];
echo $newvar;
?>

0
 
LVL 7

Expert Comment

by:kohashi
ID: 9714255
      $parts = split ("=", $_SERVER['QUERY_STRING'];);
       $total = count($parts) - 1;
       $fieldyouwant = $parts[$total];


$fieldyouwant will contain that '1' that you needed.  It will not work if there is more than one field being passed.  Then you will have to do $parts[$total-whatever] as well to get the other variables.  It basically splits it apart between = signs.  I cannot remember if a '\' is needed before the '=' sign.  


hope that helps,
-kohashi
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

730 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