PHPLRNR Posted July 25, 2008 Share Posted July 25, 2008 Hi, Is there any other way to forward from one page to another page in PHP except header( 'Location: http://www.mysite.net/mypage.htm' ) and using <META> tag. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/ Share on other sites More sharing options...
Xurion Posted July 25, 2008 Share Posted July 25, 2008 Not that I know of - why can't you use header? Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-599497 Share on other sites More sharing options...
Skittalz Posted July 25, 2008 Share Posted July 25, 2008 Yes there is buddy <?php // Put this code in the header of your HTML file * Edit PHP as needed// echo "<script language=\"Javascript\"> function forward(){ location.href="http://www.website.com"; } </script>"; To forward when a user clicks a button, in the button tag include -- onClick = "forward()"; To forward automatically after so many seconds add this to the body tag onload=setTimeout('forward()',5000) Where '5000' means 5 seconds [1000 = 1 sec] Hope this helps Steve Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-599552 Share on other sites More sharing options...
Xurion Posted July 28, 2008 Share Posted July 28, 2008 Is there any other way to forward from one page to another page in PHP Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-601472 Share on other sites More sharing options...
Skittalz Posted August 7, 2008 Share Posted August 7, 2008 <META> Tags aren't PHP either .... just trying to be creative and help someone out ... but yeah Xurion, thinkin inside the box usually solves the problem Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610784 Share on other sites More sharing options...
Xurion Posted August 7, 2008 Share Posted August 7, 2008 META isn't PHP either... Only way to forward to another page (with PHP only) is to header('location: yourpage.php') Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610839 Share on other sites More sharing options...
lemmin Posted August 7, 2008 Share Posted August 7, 2008 But if you do this, it does effectively forward: echo "<script type="text/JScript">self.location=\"newpage.php\"</script>"; Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610856 Share on other sites More sharing options...
Xurion Posted August 7, 2008 Share Posted August 7, 2008 True, but why break the back button on the browser when there is no need? Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610861 Share on other sites More sharing options...
Skittalz Posted August 7, 2008 Share Posted August 7, 2008 Lol if you want to get technical he said in PHP ahem in - not with I also find it amusing your critiquing me for using javascript when we are in the javascript forum ... I think the author was trying to say something ... <META> Tags aren't PHP either.... just trying to be creative and help someone out ... but yeah Xurion, thinkin inside the box usually solves the problem META isn't PHP either... Only way to forward to another page (with PHP only) is to header('location: yourpage.php') Meta tags aren't php???? Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610865 Share on other sites More sharing options...
Xurion Posted August 7, 2008 Share Posted August 7, 2008 Meta tags are not PHP, they are HTML. Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610870 Share on other sites More sharing options...
Skittalz Posted August 7, 2008 Share Posted August 7, 2008 aren't = are not now try reading this post again Quote from: Skittalz on Today at 10:08:47 AM <META> Tags aren't PHP either.... just trying to be creative and help someone out ... but yeah Xurion, thinkin inside the box usually solves the problem Quote from: Xurion on Today at 10:47:18 AM META isn't PHP either... Only way to forward to another page (with PHP only) is to header('location: yourpage.php') Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610927 Share on other sites More sharing options...
haku Posted August 7, 2008 Share Posted August 7, 2008 Javascript redirects are no good because they won't work if the user has javascript turned off, and search engines really don't like them. They don't like meta redirects either. Headers are definitely the way to go. Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610931 Share on other sites More sharing options...
Skittalz Posted August 7, 2008 Share Posted August 7, 2008 Yes, but it must be called before any actual output is sent. There are alot of instances in which this is the case... so in those instances javascript would be key ... I believe the author of this post must have ran into on of these instances hence why he asked an alternative way to forward pages Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610942 Share on other sites More sharing options...
KevinM1 Posted August 7, 2008 Share Posted August 7, 2008 Yes, but it must be called before any actual output is sent. There are alot of instances in which this is the case... so in those instances javascript would be key ... I believe the author of this post must have ran into on of these instances hence why he asked an alternative way to forward pages Then better application design is needed, not a JavaScript workaround that dosen't address the cause of the potential 'headers already sent' problem. A well designed application processes requests first, then renders output, thus avoiding the problem entirely. Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610953 Share on other sites More sharing options...
Skittalz Posted August 7, 2008 Share Posted August 7, 2008 Or he could use javascript which does what he wants it to do effectively without any errors and without reconstructing his program. Why make this harder then it needs to be? Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-610976 Share on other sites More sharing options...
haku Posted August 8, 2008 Share Posted August 8, 2008 I agree with Nightslyr. Header redirects can always be done before output is sent to the browser if the application is designed well. Or he could use javascript which does what he wants it to do effectively without any errors and without reconstructing his program. Why make this harder then it needs to be? For the exact reasons I said before: 1) If the user has javascript turned off in their browser (and noscript is one of the most popular firefox plugins there are), the redirect won't work. 2) Search engines don't use javascript, so the redirect will fail for them, leaving any data on the other side of the redirect effectively invisible to the search engines. On top of this, I've read that the search engines actually penalize for javascript AND metatag redirects. So for anyone who is concerned with getting a good ranking, they would be better off using php headers. It's not a matter of making things harder than they need to be, it's a matter of using the most reliable, search-engine friendly method. Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-611352 Share on other sites More sharing options...
KevinM1 Posted August 8, 2008 Share Posted August 8, 2008 Not only that, but a lot of the issues that come up in this forum are directly related to application design. I mean, how many threads have been started that are basically "Help, I can't get my JavaScript and PHP to behave properly?" I believe that stressing good application design, in conjunction with helping them with their immediate coding problem, is a better solution than just giving them the code to fix it. That's one of the reasons why I cringe whenever I see people give code like: <body onload="someInitFunction();"> . . . <?php while($row = mysql_fetch_assoc($result)) { echo "<a href=\"{$row['url']}\">{$row['linkName']}</a>"; } ?> . . . <input type="submit" name="submit" value="Submit" onclick="alert('You clicked me!'); return false;" /> This is NOT GOOD DESIGN!!!!! It's hard to edit, hard to debug, and necessitates copy-&-paste coding, which is bad. Separating the code into logical segments produces much better results: <?php . . . $output = ""; while($row = mysql_fetch_assoc($result)) { $output .= "<a href=\"{$row['url']}\">{$row['linkName']}</a>"; } . . . ?> <html> <head> <script type="text/javascript"> function someInitFunction() { var submit = document.getElementById('submit'); function showAlert() { alert('You clicked me!'); return false; } submit.onclick = showAlert; } window.onload = someInitFunction; </script> </head> <body> . . . <?php echo $output; ?> . . . <input type="submit" name="submit" id="submit" value="Submit" /> </body> </html> Yes, the JavaScript code is longer than what you'd get if you embedded it, but it's all in one centralized location, meaning it can be extracted into an external file you can use in multiple pages. Not only that, but the JavaScript is completely separate from both the static markup and the markup generated by PHP, so it's easier to follow what the script is doing. Now, obviously, in a contrived, just-off-the-top-of-my-head example like this, the benefits to this approach may not be very evident. But there's a reason why the professionals stress developing in terms of tiers, and in using unobtrusive methods to render output. Now, regarding the OP, it could be, as Skittalz said, that they need immediate results. Fine. But other forces will tug at the seams of the OP's application. Good design application future-proofs projects from these forces. So, maybe the band-aid will work here. But as issues come up, and band-aids become harder and harder to integrate into the core application, they'll probably wish they took the time to properly design their site. So, in the end, they'll be hit twice - once for all of the little tweaks and fixes that they employ, and once for finally biting the bullet and designing their app the right way, which they should've done at the beginning. I don't mean to rant, but shrugging off the importance of application design when helping people who obviously need to rethink the direction of their project is the exact opposite of how we should help them. If it's a matter of them being under a deadline...well, maybe they shouldn't have accepted a project from a paying client that's beyond their current skill level. Just my $0.02. Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-611854 Share on other sites More sharing options...
PHPLRNR Posted August 9, 2008 Author Share Posted August 9, 2008 I have used header, but it makes problem like below: I have given a condition to access header portion, but it does not work only for that condition. Though the condition satisfy or not but page forward using header. Here is the code $chk = $_POST["jschk"]; if ($chk != '1') { header( 'Location: http://www.mydomain.net/mypage.htm' ) ; } Though the upper condition satisfy or not but page forwarded to mypage.htm page. How I will solve this problem? Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-612202 Share on other sites More sharing options...
haku Posted August 11, 2008 Share Posted August 11, 2008 I'm sorry, it was a little difficult to understand your English, so I may have misunderstood you, but I think that you want to change this: if ($chk != '1') to this: if ($chk != 1) In your code, you are checking for text that is '1'. But I think you want to check for a numeric value of one. Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-613207 Share on other sites More sharing options...
Xurion Posted August 12, 2008 Share Posted August 12, 2008 Why make this harder then it needs to be? Because it's the correct way? Quote Link to comment https://forums.phpfreaks.com/topic/116569-forward-to-another-page/#findComment-614378 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.