Plinpod Posted September 15, 2009 Share Posted September 15, 2009 Hello, Ok so I am modifying a script and im having some trouble. I created a function that will echo a java script which grabs the url that a user has just arrived from here is this function. function prevurl() { $language = "javascript"; ob_start(); echo "<script language=$language> document.write(document.referrer); </script>"; $link = (string)ob_get_contents(); ob_end_clean(); return $link; } I later call this function and assign the return to a variable, I test the variable to make sure that is has the right content, when tested in the browser the test string displays a URL (the correct thing) $buffer = prevurl(); $values[0] = $buffer; // echo "$url"; $value = $buffer; echo "Checking Value: $value"; //THIS PART WORKS and displays the correct value So now I need to apply this value into a form along with some other variables Here is an example of how this code looks $html = '<input type="text" name="' . $name . '" value="' . esc_attr($value) . '"' . $atts . ' />'; //when value is passed here it doesn't display the correct value BUT the value that is now passed through $value is no longer the URL but the script that was written in the echo. Instead of displaying a URL inside the form it displays this <script language=$language> document.write(document.referrer); </script> Why is this and how can I fix it, please help. Thank You Quote Link to comment https://forums.phpfreaks.com/topic/174263-variable-tracing-back-to-echo-help/ Share on other sites More sharing options...
RussellReal Posted September 15, 2009 Share Posted September 15, 2009 use $_SERVER['HTTP_REFERER'] echoing javascript will only be seen and evaluated after php has exited, so your obgetcontents won't work.. Quote Link to comment https://forums.phpfreaks.com/topic/174263-variable-tracing-back-to-echo-help/#findComment-918717 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.