In same window. And if posible an example please.
how make php code to open an URL
The header command is the command that redirects to a URL, when you run this command, the php will be interrupted and the URL in the header command will show up..
I can't code anything right now (I'm @ work) but I don't think a example will do you any good, it's just a command that u use in between the php-tags, no big deal
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if (condition) {
header("Location: [url]http://www.website.com/webpage.html[/url]");
}
?>
</body>
</html>
Something like this? Just short exapple as for newbie...
That above example would cause a fatal error. The header function cannot be sent aftre outputs have already been sent to the browser. In this case anything before the <?php.
even a space would cause a fatal error. It would work like this however:
<?php
if (condition) {
header ("Location: pagetobesentto.php");
}
?>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
Okay, now my turn : see attachment: unzip en set on your localroot... Run the program to see if it works, check the code (I kept it as simple as I could) to see how it works
the page doesn't do much more then ask you to enter a line of text, and If you do, then you will be redirected to the phpbuilders site if not you'll just get the message saying you typed the wrong text. Very plain and simple
I couldn't check if the php works though (@ work as I said earlier) but it's pretty logic
Thanks, it help
But why not to go further and make it more usefull?
- make it as function and call if condition is ok:
<?php fuction aaa() { header ("Location: pagetobesentto.php"); } ?> <html> <head> <title></title> </head> <body> <?php if (condition) {aaa()} </body> </html>
Somethink like that?
- how to open a new page after same time (20seconds)( something like redirect)?
Make it even more useful
<?php
fuction aaa($where) {
header ("Location: "$where);
}
?>
it's works!!!
OK, now I can use it just before normal HTML page sends its HEADER. So how to open some page in the midle of HTML code?
Us I just readed in PHP manual from http://www.php.net/:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
As you see, I can't use it after normal output is send.
So how to solve this problem?
And second: how to redirect site to another location after 20sec.?
Thanks
you can use output buffering, when i find the command i will tell ya!
Hey everyone,
The info you posted was very helpful to me.
I do have a couple of questions though.
1) How do you open a new page? (i.e., target="_blank")
2) Why doesn't the new URL show up in the address box on the browser?
3) Any advice on placement of the code as it seems to be very touchy about where it is placed. I need to have HTML code in with the script and I always receive the error message: PHP Warning: Cannot add header information - headers already sent by (output started at ...
Thanks for help,
Gary
<?php
$status = "yes";
$menu = "http://www.sun.com";
if ($status != "")
{
goto_URL($menu);
}
?>
<?php
function goto_URL($menu)
{
header ("Location: $menu");
}
?>
1) How do you open a new page? (i.e., target="_blank")
you mean new window?
If so then you will need to load a page containing javascript.
2) Why doesn't the new URL show up in the address box on the browser?
basically this happens
Browser: Mr Server can i have page.php
Server: Yes let me run it through the PHP program
[Stage Directions: Server to go to next.php]
Server: Here is the page you asked for
Browser Thanks.
So the browser know nothing about the redirect
3) Any advice on placement of the code as it seems to be very touchy about where it is placed. I need to have HTML code in with the script and I always receive the error message: PHP Warning: Cannot add header information - headers already sent by (output started at ...
There is a link to a tut on the index page whic covers output buttering used properly this wil stop header problems.
Have fun
Man I know that you meant
let's go!
you can try it
we go use php and javascript
<?
if (condition)
{
echo "<script> window.location('url here');</script>" ;
}
good luck !
werkkrew
THANK U VERY MUCH BCZ OF U ILL GET FULL IN MY MULTIMEDIA PROJECT BHSDK