Jump to content

Fetching the Site URL


Dev01

Recommended Posts

Hi all

 

New to PHP ...

 

How would I use a site_url function to call the URL of my website. For example:

 

<?php echo site_url('login.php') ?>

 

Placing the statement above simply results in an error, undefined function.

 

Thanks very much in advance

Link to comment
Share on other sites

You didn't define the function.

 

I'm not sure exactly what you're looking for, but if you're just wanting to use php to get the url or the page where the script is executing, look for what you want in the $_SERVER array (google $_SERVER and read the php manual -- it gives good examples).  Some will give the complete path, some the domain name only, some the script only...etc.

 

For example:

<?php
echo $_SERVER['SERVER_NAME'];
?>

should give you something like www.example.com

therefore...

<?php
$mysite=$_SERVER['SERVER_NAME'];
echo "My website is: $mysite";
?>

should give you something like:

My website is: www.example.com

 

header('Location: login.php'); will forcefully redirect your users to the login.php page.

 

If this is what you want to do, be sure to do this before any output and follow it immediately with exit;

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.