subhomoy Posted September 9, 2013 Share Posted September 9, 2013 Hello every one... How to pass values from one page to another page without using form or any kind of click... I can load an external php page like this <-----------a.php---------------> <html> <body> <?php require_once "abc.php"; ?> </body> </html> but i want to pass values in the same manner as the page is loaded. <?php require_once "abc.php?value =111"; ?> and the abc.php page should grab the values send and show in the same page ie in (a.php) in the abc.php page <?php echo $val = $_REQUEST ['value']; ?> but i'm getting error.... every thing should happen whenever the page reloads or refreshes... I dont want to use any kind of action.. (i.e click or form) Thank in advance,,, Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 9, 2013 Share Posted September 9, 2013 And the error is......!? hmm...needs a drum-roll I think..... Quote Link to comment Share on other sites More sharing options...
subhomoy Posted September 9, 2013 Author Share Posted September 9, 2013 sorry to post the error Warning: require_once(a.php?value=subhomoy) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\OOP_IN_PHP\index.php on line 10 Fatal error: require_once() [function.require]: Failed opening required 'a.php?value=subhomoy' (include_path='.;\xampp\php\PEAR') in C:\xampp\htdocs\OOP_IN_PHP\index.php on line 10 Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 9, 2013 Share Posted September 9, 2013 the warning kinda says it all - the file name does not exist. you can't use require or include to pass variables into files like that because at the point that the require/include is called they are not being sent as variables, but as a literal part of the file name. You need to parse the variables through a url so that the http protocol passes the header info needed and the script has access to the variable information that you are trying to send. What exactly is your objective here? and have you ever used cURL or written and JQuery/javascript before? Quote Link to comment Share on other sites More sharing options...
subhomoy Posted September 9, 2013 Author Share Posted September 9, 2013 yeah i know javascript and jquery... Can u plz guide me with it... Actually i want to create an advertising site (as our final year project) where i'll be placing the code and based on the information passed as values the type of ads will appear.. I'll place <?php require_once "abc.php?type=468x60&id=2"; ?> like that.. similar to like this... <script type="text/javascript" src="http://syndication.exoclick.com/ads.php?type=468x60&login=subhomoy123&cat=472&search=&ad_title_color=0000cc&bgcolor=FFFFFF&border=0&border_color=000000&font=&block_keywords=&ad_text_color=000000&ad_durl_color=008000&adult=1&sub=&text_only=0&show_thumb=&idzone=681589&idsite=235181"></script> but i dont know why they have used javascript and src as a php page... Hope u understood.... By the way thanks for the reply... Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 9, 2013 Share Posted September 9, 2013 but i want to pass values in the same manner as the page is loaded. You can', and you don't have to. When you do a require on a file (you are not using a URL here) then the code of the script you are "requiring" becomes part of the script that you do the require in. So, all variables, all code, everything is already available. This works: index.php: <?php $foo = "bar"; require_once("foopy.php"); ?> foopy.php: <?php echo $foo; ?> The parameters that you use are only required when "require" load a URL, which you should *never* do unless you have absolute control over the URL and remote server. Also, never use a URL to access content on the same server, it's a huge waste or resources. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 10, 2013 Share Posted September 10, 2013 you could echo an AJAX request using the php script to populate the variables from the $_GET array on the current page to subload a section of the page using the data. Although as vinny said, it's not really the best use of resource. if you want the code in the include to use the data on the current page all you should need to do is include the file it's self, no url data needed. Here's the AJAX anyway. $ajax = <<<AJAX_STR <script type="text/javascript"> $(document).ready(function(){ $.ajax({ url: "your_url.php?value={$_GET['value']}", type: "get", success: function(data){ $('#displayDIVid').html(data); }, error: function(){ alert("Some items could not be displayed."); } }); }); </script> AJAX_STR; echo $ajax; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.