Hi Experts,
I am new to PHP. I just want to know, how can we advance from one page to another (without a form submit) from within PHP, like <jsp:forward> does in JSP? If it is possible in PHP, please also tell how we can send parameters to the new page, like <jsp:forward> send with <jsp:param> tags? the jsp example which I want to convert in PHP is as follow:
<jsp:forward page="user_db_login.jsp" flush="true">
<jsp:param name="username" value="<%= strName %>" />
<jsp:param name="password" value="<%= strPwd %>" />
<jsp:param name="DatabaseString" value="<%= strDbstr %>" />
</jsp:include>
An early response will be greatly appreciated.
Thanks in advance.
What is PHP equivalent for <jsp:forward> ???
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: What is PHP equivalent for <jsp:forward> ???
Code: Select all
header('Location: http://www.example.com/user_db_login.php');mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: What is PHP equivalent for <jsp:forward> ???
Thank you very much. But here is another question. If we append parameter values to the URL as query string, it will only work with pages which accept parameters with GET method.... what about if the target page is expecting parameters by POST method?
Thanks again.
Thanks again.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: What is PHP equivalent for <jsp:forward> ???
The location header sends a header to the client browser telling it to redirect there. There is no header to redirect a browser and send post data. You can send post data from the server, but this does not redirect the browser. I would use: http_post_fields() or if you want to send a string of pre-encoded data: http_post_data().
To actually get the browser to post to a page you would have to use client side javascript.
To actually get the browser to post to a page you would have to use client side javascript.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: What is PHP equivalent for <jsp:forward> ???
Which I believe JSP does. Languages with custom controls like these (also in ASPX pages) replace those custom tags of yours with client-side Javascript to generate the effect that they need. Look at the page source of a JSP or ASPX page and you'll see Javascript pages included in your HTML output.
You can do the same thing with PHP. Just develop a template parser that takes custom HTML tags and replace it with prebaked code and Javascript. Prado does this to great effect.
You can do the same thing with PHP. Just develop a template parser that takes custom HTML tags and replace it with prebaked code and Javascript. Prado does this to great effect.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: What is PHP equivalent for <jsp:forward> ???
I was looking through some old code for this. Quick and dirty, needs cleanup:
Code: Select all
function http_post_redirect($url='', $data=array(), $doc=false) {
$data = json_encode($data);
if($doc) {
echo "<html><head></head><body>";
}
echo "
<script type='text/javascript'>
var data = eval('(' + '$data' + ')');
var jsForm = document.createElement('form');
jsForm.method = 'post';
jsForm.action = '$url';
for (var name in data) {
var jsInput = document.createElement('hidden');
jsInput.setAttribute('name', name);
jsInput.setAttribute('value', data[name]);
jsForm.appendChild(jsInput);
}
document.body.appendChild(jsForm);
jsForm.submit();
</script>";
if($doc) {
echo "</body></html>";
}
exit;
}
Last edited by AbraCadaver on Mon Apr 12, 2010 1:04 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: What is PHP equivalent for <jsp:forward> ???
Thank you very very much for the script. Its really nice.