Solved

how to get URL variable

Posted on 2003-11-01
7
249 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

809 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