Page 1 of 1

livecode server URL redirect?

Posted: Mon Aug 31, 2015 4:54 pm
by sms5138
Hi i wonder if anyone could tell me if there would be a way to write a redirect into a .lc script?

essentially make it to where if a variable is not present it would redirect to another URL. an example of this (on its simplest terms) can be seen below:

Code: Select all

<?lc

put $_POST["variable"] into tVariable

if tVariableis is "whatever" then
do something
else
redirect to url
end if

?>
I've found this bit of code:

Code: Select all

<?lc 
put header "Location: http://www.google.com" 
?>
source: http://activethought.net/livecode-serve ... redirects/

But it doesn't seem to redirect... Thought i'd see if anyone had any suggestions?

thanks in advance!

-Sean

Re: livecode server URL redirect?

Posted: Mon Aug 31, 2015 5:13 pm
by sms5138
Actually looks like i may have found something that works here: http://runtime-revolution.278305.n4.nab ... 71107.html

Code: Select all

put "<?xml version='1.0' encoding='UTF-8' ?>   CR" & \
         "<!DOCTYPE html>   CR<html xmlns='http://www.w3.org/1999/xhtml'>   CR" &  \
           "<head>   CR<meta http-equiv='content-type' content='text/html; charset=UTF-8' />   CR" & \
             "<meta http-equiv='refresh' content='0; url=http://www.YOURREDIRECTPAGEHERE.com/' />   CR" & \
              "<title>widestep</title>   CR<meta name='robots' content='all' />   CR" & \
               "</head>   CR<html><body> </body></html>" 
Not sure if there's a better way to do it, but wanted to post what i found to work in case someone else could use it...

-Sean

Re: livecode server URL redirect?

Posted: Mon Aug 31, 2015 11:37 pm
by ghettocottage
Just out of curiosity, what is it you are doing? Are you sending people to a different website to keep people off of your server, or another page on your site?

Re: livecode server URL redirect?

Posted: Thu Sep 03, 2015 3:45 pm
by sms5138
I'm looking to do this (as an additional step) to redirect someone from accessing this URL without going through my app.

so i guess in some ways yeah (depending on the URL used in the app) to help keep them off. so if they get to it, and can see something that is intended to be viewed from the app it'll throw them to my homepage...

My initial trip into this little side street came from this site: http://activethought.net/livecode-serve ... redirects/

Am i wrong in my thinking, or do you have any suggestions?

Re: livecode server URL redirect?

Posted: Thu Sep 03, 2015 5:16 pm
by Klaus
Hi friends,

after looking desperately for a reference to databases I did not find any,
so I will move this thread to the "CGIs and the Server" forum! 8)


Best

Klaus

Re: livecode server URL redirect?

Posted: Thu Sep 03, 2015 5:45 pm
by sms5138
Thanks Klaus,

My apologies for posting it in the wrong spot originally! :oops:

-Sean

Re: livecode server URL redirect?

Posted: Thu Sep 03, 2015 5:53 pm
by Klaus
Thou shalt be forgiven! :D

Re: livecode server URL redirect?

Posted: Thu Sep 03, 2015 6:06 pm
by ghettocottage
Something more simple could be to do the test, and if variable is not present, then just show some simple html website, but if the variable is present, then include some additional files where the rest of your lc code is :

Code: Select all

<?lc
 	--test if this is an api call
	   put $_POST["variable"] into tVariable
           if tVariable is not empty
                then  include "somefolder/otherfilewithstuff.lc"
	     else			   
 	 --end test
?>

<html>
   <head>
   </head>
  <body>
	<header>
        </header>
           <div>
		<h1>Welcome to my website</h1>
                  <p>
			Hello, this is a website
		 </p>

	   </div>
  	<footer>
  	</footer>
  </body>
</html>


Re: livecode server URL redirect?

Posted: Thu Sep 03, 2015 7:21 pm
by sms5138
Thanks! that's a really good idea. I'm gonna have to give that a shot!

Re: livecode server URL redirect?

Posted: Thu Sep 03, 2015 9:58 pm
by SparkOut
Redirect should work, but it is vital to set and output the header before ANYTHING else emitted by the server, EVEN whitespace.
An extra blank line between ?> and another <?lc opening tag will break the redirection.
You could try an lc file that JUST outputs the redirect header to test, then go through your additional tests to add checks one by one.

Re: livecode server URL redirect?

Posted: Tue Aug 11, 2020 9:58 am
by TorstenHolmer
Hi,

here is the code, I am using and which works on the current Livecode server version:

Code: Select all

<?lc
put "https://theUrlTheBrowserIsRedirectedTo" into tURL
put header "Status: 301"
put header "Location:" && tURL
?>  
Cheers,
Torsten