Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to get URL variable

Posted on 2003-11-01
7
Medium Priority
?
253 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
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

604 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