i am a real noob in php
i have a php url say
if i give zzz at the end of the url like this
the output is yyy
i want a script to get the zzz from another script using $_REQUEST
and the final output of the script should be yyy

i tried this but it didnt work
<?php echo ?>

Dani AI

Generated

Short note referencing the thread: correctly explained that URL parameters are key=value pairs and that the value appears in the query string; solved the problem by redirecting with the parameter appended. For maintainable and safe code, prefer reading a GET parameter explicitly and validating it, rather than using $_REQUEST (which merges GET, POST and COOKIE and can lead to unexpected values — see the PHP manual on $_REQUEST).

A safe pattern to follow:

  • read the query parameter with filter_input or $_GET,
  • validate or whitelist the value (regex or a map of allowed targets),
  • URL-encode the value,
  • send the redirect header and terminate the script.

Example (adjust validation/whitelist to your needs):

<?php
$chat = filter_input(INPUT_GET, 'chat', FILTER_DEFAULT);

if (empty($chat) || !preg_match('/^[A-Za-z0-9_-]+$/', $chat)) {
    http_response_code(400);
    echo 'Invalid or missing chat id';
    exit;
}

$target = '/chat.php?chat=' . rawurlencode($chat);
header('Location: ' . $target, true, 302);
exit;
?>

Notes and cautions:

  • Use rawurlencode() when inserting user data into a URL (see rawurlencode).
  • Call exit after header('Location: ...') so the script stops.
  • Make sure no output (including BOM or stray whitespace) is sent before calling header() (see header docs).
  • Avoid open-redirect vulnerabilities by not accepting arbitrary external URLs from users; use a whitelist or map short IDs to known targets (see OWASP on unvalidated redirects).

References: PHP $_REQUEST (reserved variables), filter_input, header, rawurlencode, and OWASP guidance on redirects.

Recommended Answers

All 2 Replies

Basically the way that it works is everything after the ? is a set of key-value pairs. So, if you need to find $_REQUEST["msg"] you need the URL to read

Hope this helps,
darkagn

i got it solved
the format should be

<?php 
header('Location: '.$_REQUEST['msg'].'');
?>

simple :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.