Are you using LiveCode to create server scripts or CGIs?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
sms5138
- Posts: 126
- Joined: Mon Feb 23, 2015 11:49 pm
Post
by sms5138 » Mon Aug 31, 2015 4:54 pm
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
-
sms5138
- Posts: 126
- Joined: Mon Feb 23, 2015 11:49 pm
Post
by sms5138 » Mon Aug 31, 2015 5:13 pm
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
-
ghettocottage
- Livecode Opensource Backer
- Posts: 366
- Joined: Tue Apr 10, 2012 9:18 am
Post
by ghettocottage » Mon Aug 31, 2015 11:37 pm
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?
-
sms5138
- Posts: 126
- Joined: Mon Feb 23, 2015 11:49 pm
Post
by sms5138 » Thu Sep 03, 2015 3:45 pm
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?
-
Klaus
- Posts: 13854
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Thu Sep 03, 2015 5:16 pm
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!
Best
Klaus
-
sms5138
- Posts: 126
- Joined: Mon Feb 23, 2015 11:49 pm
Post
by sms5138 » Thu Sep 03, 2015 5:45 pm
Thanks Klaus,
My apologies for posting it in the wrong spot originally!
-Sean
-
Klaus
- Posts: 13854
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Thu Sep 03, 2015 5:53 pm
Thou shalt be forgiven!
-
ghettocottage
- Livecode Opensource Backer
- Posts: 366
- Joined: Tue Apr 10, 2012 9:18 am
Post
by ghettocottage » Thu Sep 03, 2015 6:06 pm
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>
-
sms5138
- Posts: 126
- Joined: Mon Feb 23, 2015 11:49 pm
Post
by sms5138 » Thu Sep 03, 2015 7:21 pm
Thanks! that's a really good idea. I'm gonna have to give that a shot!
-
SparkOut
- Posts: 2856
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Thu Sep 03, 2015 9:58 pm
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.
-
TorstenHolmer
- Posts: 57
- Joined: Mon Oct 28, 2013 1:23 pm
- Location: Dresden, Germany
Post
by TorstenHolmer » Tue Aug 11, 2020 9:58 am
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