code_legend
code_legend

Reputation: 3285

PHP GET variable from another page

I have the following lines:

if(isset($_GET['search'])){
  $search_query = $_GET['user_query'];

The problem is that I am not trying to retrieve the get variable from this page, but rather from searchPage.php, which is a currently different page located within the same folder. So I would it to get the user_query variable from that page instead. Where for instance, in that page I have:

searchPage.php?user_query=microsoft&search=search

If you need any clarification, let me know.

Upvotes: -1

Views: 86

Answers (1)

Mike Miller
Mike Miller

Reputation: 3129

Seems weird but if you must do it like this whats wrong with just redirecting from searchPage.php to the page where you want to get parameter to be eg

In searchPage.php

 header("Location:the_other_script.php?user_query=".$_GET['search']);

And in the_other_script.php

 if(isset($_GET['user_query']){
    $user_query = $_GET['user_query'];
 }

Begs the question why not just do your logic in searchPage.php? If you want to separate your code out just use a function call in searchPage.php.

EDIT:

So you have another script file called functions.php.. In this case just require this file in searchPage.php like..

require_once('the/path/to/functions.php');

and in your searchPage.php

 if(isset($_GET['user_query']){
    $returned_from_function = a_function_from_your_functions($_GET['user_query']);
    //do some stuff
 }
 //do some other stuff

In functions.php

 function a_function_from_your_functions($user_query){ 
  //do what you need to do 
  return $something; //optionally 
  }

Upvotes: 1

Related Questions