Calling Functions in using PHP

Asked By 20 points N/A Posted on -
qa-featured

Hello!

I’m new to PHP and I’m using Header Function in calling PHP pages.

I want to know what other functions or other alternative codes that can be used which is the same with header Function.

SHARE
Best Answer by Cyril L Edmonds
Answered By 45 points N/A #103384

Calling Functions in using PHP

qa-featured

Hello there Philippe,

Header functions in PHP only sends raw HTTP header. There is another way to include PHP pages in your site. You may use the include and require functions of PHP.

This will help you include other PHP files into your browser. 

For example: Create a PHP file and save it as menu.php

echo "<a href="/default.php">Home</a>
<a href="/tutorials.php">Tutorials</a>
<a href="/references.php">References</a>
<a href="/examples.php">Examples</a> 
<a href="/about.php">About Us</a> 
<a href="/contact.php">Contact Us</a>';

and in your PHP file write this code:

<html>

<body>

<div class="leftmenu">

<?php include 'menu.php';?>

</div>

</body></html>

Hope it helps you.

Regards Roland.

Best Answer
Best Answer
Answered By 80 points N/A #103385

Calling Functions in using PHP

qa-featured

Greetings Philippe So,

One other way to call PHP functions in your page is through JQuery using the $.ajax function. This function has a lot of options and you can learn about it here http://api.jquery.com/jQuery.ajax/. Example of calling a PHP function through $.ajax

This code would need to go in the html:


var value = $.ajax({
type: "POST",
url: "some.php",
data: "name="+customvariable,
async: false
}).responseText;

Your PHP file should contain then this:

if(isset($_POST['name']))
{
$id = mysql_real_escape_string($_POST['name']);
$ret = array() ;
$sSQL = "SELECT * FROM produit WHERE prod_code = '$id' LIMIT 1" ;
$this->db->query($sSQL) ;
$ret['cnt'] = $this->db->num_rows() ;
echo $ret;
}

As I said, this function has a lot of types of data you can use with $.ajax. Visit the above mentioned link if you wish to learn more about it.
I hope I have helped you with your question.
Regards,

Answered By 0 points N/A #195584

Calling Functions in using PHP

qa-featured

Hi,

If you want function for redirectiong page to another page, there are many functions in php like Header().

You can use HTML <a></a> to give a link to user and by clicking on that user will transfer to that page.

<a href="home.php">Home</a>

Here in "href" you have to give your pagename.

There in one another code of javascript which will give you output like header.

<script type="text/javascript">

Location.href="home.php"

</script>

Related Questions