Jump to content

Variable as website...


dannyluked

Recommended Posts

Hi,

I have this code;

 <?php
if(!$_POST[id]){
header('Location: HTTP://EXAMPLE.COM');exit;
}else{
}
?>

 

The code works fine! I was just wondering how I can change the 'http://example.com' to a variable that is in a seperate file (config.php)?

I am guessing it is something like this although this code dosent work!

 

 <?php
include "config.php";
if(!$_POST[id]){
header('Location: $thesite');exit;
}else{
}
?>

Link to comment
https://forums.phpfreaks.com/topic/183302-variable-as-website/
Share on other sites

in theory will work, if done right.  you can't use single-quotes in this situation.  you can use double-quotes as any PHP within double-quotes will be parsed, or you can use concatenation:

 

 <?php
include "config.php";
if(!$_POST[id]){
     header('Location:' . $thesite); exit;
}else{
}
?>

 

-OR-

 

 <?php
include "config.php";
if(!$_POST[id]){
     header("Location: $thesite");exit;
}else{
}
?>

 

all assuming $thesite has been declared in config.php

Link to comment
https://forums.phpfreaks.com/topic/183302-variable-as-website/#findComment-967529
Share on other sites

using concatenation/string operators:

 

 <?php
include "config.php";
if(!$_POST[id]){
     header('Location:' . $thesite . '/FOLDER'); exit;
}else{
}
?>

 

-AND-

 

 <?php
include "config.php";
if(!$_POST[id]){
     header("Location: $thesite/FOLDER"); exit;
}else{
}
?>

Link to comment
https://forums.phpfreaks.com/topic/183302-variable-as-website/#findComment-967539
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.