Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

How to call a new page from a function not a form

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

How to call a new page from a function not a form

Postby usdr » Sun Dec 29, 2002 3:00 pm

I know how to call a new php script in response to a user pressing a button, but how do I call a new script from within a function as a response to a time funtion etc.

ie
function XYZ() {
/* go to a new page NOW */
}

I have looked up all the books on php that I have (6) but I didnt search the web because I have no idea what the keywords to use are.

I have only been doing php for a couple of weeks, so if there is an answer could you please make it understandable by a newbie?

Thanks

Dave
usdr
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Dec 24, 2002 6:46 pm

Postby Joan Garnet » Sun Dec 29, 2002 3:10 pm

If the action happens in the users browser, then you'll have to use javascript or ActionScript.
php is a server side language, so things happen only when you link that script in the server.
:)
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby usdr » Sun Dec 29, 2002 3:16 pm

So within function XYZ () I have to use javascript?

ie.

function XYZ() {
?>
<script language=javascript>

// Call the myscript.php here ///

</script>
<?
}

Any ideas on how to call a php script from javascript?
I know less about JS than php.

BTW. If I have no problem getting to the function, it is just calling the other script.

That is, my first php script will respond to a time change without user input (server side?) and I want it to then respond my running a second script with or without the end user.


Thanks

Dave
usdr
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Dec 24, 2002 6:46 pm

Postby Joan Garnet » Sun Dec 29, 2002 4:53 pm

You can use setTimeout

Code: Select all
<script language="javascript">
function call_script(){
     document.location = "my_script.php?my_var1=blahblah&my_var2=blahblah";
}
</script>
</head>
<body onload="window.setTimeout('call_script();' , 1500 );">


After 1500 miliseconds the user got in this page, he will be redirected to my_script.php and all those URL vars will be interpreted by php as $HTTP_POST_VARS["my_var1"] and $HTTP_POST_VARS["my_var2"].

This is just an example, then you can pass arguments to the function so you can use for example a form to choose which vars you want to send, etc...

bye
:)
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby usdr » Sun Dec 29, 2002 6:55 pm

Thank you very much.

In the meantime, I experimented and got it to function using a print meta refresh command

But I think that I will change it to your thought

Thanks
Dave
usdr
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Dec 24, 2002 6:46 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron