asmith Posted November 27, 2007 Share Posted November 27, 2007 how can i tell php to run a link ? like : if ($a = "hello") { //goto "yahoo.com" else {//goto "gmail.com" of course i don't mean : header(location : ) in header there should be nothing even a space before it , i mean just simply run a link . ! Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 please explain RUN ??? what event do you want the link to run on Quote Link to comment Share on other sites More sharing options...
asmith Posted November 27, 2007 Author Share Posted November 27, 2007 sorry my english bad i mean open that link in the same window, or new window . (same window more important to me) Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 are you trying to incorporate gmail page into your page or simply creating a link based on $a like <a href="<? if ($a = "hello") { echo "http://yahoo.com";} else {echo "http://gmail.com";} ?>"> go here </a> Quote Link to comment Share on other sites More sharing options...
asmith Posted November 27, 2007 Author Share Posted November 27, 2007 no ! the code you gave will print 2 links on the page ,then user click on them. if want php open the links automaticlly without asking the user. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 27, 2007 Share Posted November 27, 2007 This should work if ($a ="hello") { header('Location: your http page); } else { header('Location: your http page); } Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 for one thing the code i gave will only generate one link, if you notice im just if'ing the href portion of a single link, but now i understand what your wanting you can do it thru javascipt on the body tag onload event. <body onload="window.location = '<? if ($a = "hello") { echo "http://yahoo.com";} else {echo "http://gmail.com";} ?>'> Quote Link to comment Share on other sites More sharing options...
asmith Posted November 27, 2007 Author Share Posted November 27, 2007 header won't work in the middle of the html , it should be at the top . before html begins any special code that simply opens a link automaticlly anywhere on the page ? (PHP) for one thing the code i gave will only generate one link, if you notice im just if'ing the href portion of a single link, but now i understand what your wanting you can do it thru javascipt on the body tag onload event. <body onload="window.location = '<? if ($a = "hello") { echo "http://yahoo.com";} else {echo "http://gmail.com";} ?>'> it is a good code , but if the browser do not support java, it won't work . Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 you can call header tags half way down a PHP file, if you use the Output Buffering code <? ob_start(); ... lots of content here.... $location = "location: http://www.gmail.com"; ob_clean(); header('HTTP/1.0 302 Found'); header($location); ?> Quote Link to comment Share on other sites More sharing options...
asmith Posted November 27, 2007 Author Share Posted November 27, 2007 what does output buffer exactlly do ? Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 header won't work in the middle of the html , it should be at the top . before html begins any special code that simply opens a link automaticlly anywhere on the page ? (PHP) It is ilogical to attempt to display data and then redirect. What is the point of displaying something if your simply going to redirect to another page? I suggest you adjust your logic accordingly, or use the previously posted buffering hack. Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 what does output buffer exactlly do ? It buffers all output into memory, once you call ob_flush the buffer is then sent to the client in one go. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 it holds the OUTPUT in a BUFFER until it is released by an OB_FLUSH type command, but PHP auto flushes the buffer on end of the php file. I use it all the time http://www.php.net/manual/en/function.ob-start.php Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 27, 2007 Share Posted November 27, 2007 Almost any IF logic that would generate a redirection can be tested long before any output to the browser, and therefore header should work fine. You need to fix the coder PhREEEk Quote Link to comment Share on other sites More sharing options...
asmith Posted November 27, 2007 Author Share Posted November 27, 2007 header won't work in the middle of the html , it should be at the top . before html begins any special code that simply opens a link automaticlly anywhere on the page ? (PHP) It is ilogical to attempt to display data and then redirect. What is the point of displaying something if your simply going to redirect to another that's true, i just didn't want to rearrange codes !! 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.