?
Solved

how to get URL variable

Posted on 2003-11-01
7
Medium Priority
?
252 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
[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
7 Comments
 
LVL 6

Accepted Solution

by:
aolXFT earned 80 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
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