HTTP error
#1

I'm getting error 302, how can I fix the problem?

HTML Code:
format(string, sizeof(string), "mydomain.ro/sendemail.php?code=44514&EmailTo=myemail@yahoo.com&Message=Salutare DiBlaine, acesta este un test!");
for(new c; c < strlen(string)+1; c++) if(string[c] == ' ') string[c] = '+';
HTTP(playerid, HTTP_POST, string, " ", "EmailDelivered");
I try to replace HTTP_POST with HTTP_GET but nothing, same error.
Reply
#2

Could you provide the code in whatever you handle this request?
Reply
#3

Quote:
Originally Posted by Y_Less
View Post
302 isn't an error. Did you look up http codes?
Yes I searched(https://www.w3schools.com/tags/ref_httpmessages.asp)... can you help me to solve the problem? I have SSL certificate to the web.
Reply
#4

Quote:
Originally Posted by Y_Less
View Post
And what does it say about 302?
302 Found - The requested page has moved temporarily to a new URL.
I don't know how to resolve the problem...
Reply
#5

Might be something wrong within the code though...
Show us the php file where you handle this request.
Reply
#6

Quote:
Originally Posted by justinnater
View Post
Might be something wrong within the code though...
Show us the php file where you handle this request.
PHP Code:
<?php
if(isset($_GET['code'])) { //checks if request from SA:MP server contains code 
    
$code $_GET['code'];//Redefine just to look better :) 
    
if($code == 44514) { // Compare code from SA:MP request, a.k.a password to avoid spam or unauthorized requests 
        
if(isset($_GET['Message']) && !empty($_GET['Message'])) { //Checks if request from SA:MP server contains messag you want to send 
            //EmailTo[],Message[]
            
$emailto $_GET['EmailTo'];
            
$message $_GET['Message']; //Redefine just to look better :) 
            
$message str_replace("-"," ",$message); //Replace all - back to blank space as url cant contains blank spaces
            
mail($emailto"Securitate cont / Account security"$message"From: \"saveG.ro - Securitate cont / Account security\" <support@saveg.ro>\r\n" ."X-Mailer: PHP/" phpversion());//Send an email, format: To,Subject,Message,From 
            
echo "Email delivered"//Response message to SA:MP server, so server knows request was valid 
        

    } 

?>
Reply
#7

Quote:
Originally Posted by qRazor
View Post
I have SSL certificate to the web.
I think this is your problem. Because the HTTP function in samp doesn't follow redirects and you probably redirect all http requests over https with some file like .htaccess(if you use apache). Try to stop the redirect only for this url.

StackOverflow: https://stackoverflow.com/a/7073258
Quote:
Originally Posted by Eddy Freddy @ StackOverflow
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/yournonhttpsdirectory/
RewriteRule ^(.*)$ https://www.domain.xyz/$1 [R,L]
Reply
#8

Quote:
Originally Posted by Y_Less
View Post
Or, as I said, just follow the redirect!
But the only data you are given back is an html document in which there is an anchor with the new location. Then you will have to use an html parser and there is none for samp AFAIK. Or is there other easier way?
Reply
#9

Quote:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://www.vodafone.ro/mydomain/?code=44514&amp;EmailTo=myemail@yahoo.com&amp;Mess age=test">here</a>.</p>
</body></html>

Did a test, this is what comes out of it. It's what Y_Less said, follow the redirect.
Reply
#10

Quote:
Originally Posted by justinnater
View Post
Did a test, this is what comes out of it. It's what Y_Less said, follow the redirect.
How would you follow that link?

I did a test too and this is also what I get. Its clearly HTML code and not HTTP headers. You would need a html parser to get the link and then make a request again.
Reply
#11

Why not directly use the other link for your request? Am I missing something?
Reply
#12

Quote:
Originally Posted by Y_Less
View Post
If they include a body, that's up to them, but it isn't required and will be in the headers. The headers are the standardised method that computers use, the HTML is just a fallback to show the user. What you showed above is just the body.
Yes I understand that. My question is: How can you get the response headers (THE HEAD) in SA:MP?

I know Southclaws has pawn-requests. But can you get the headers without any external libraries.
Reply
#13

Quote:
Originally Posted by bgedition
View Post
I think this is your problem. Because the HTTP function in samp doesn't follow redirects and you probably redirect all http requests over https with some file like .htaccess(if you use apache). Try to stop the redirect only for this url.

StackOverflow: https://stackoverflow.com/a/7073258
Can you give me an example how I could do that at my link?
HTML Code:
mydomain.ro/sendemail.php?
Reply
#14

Quote:
Originally Posted by qRazor
View Post
Can you give me an example how I could do that at my link?
1. MAKE BACKUP of your current .htaccess file
2. find where the request is redirected to https
3. replace that part with the code bellow.
4. save and test

Code:
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/sendemail.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
Reply
#15

Quote:
Originally Posted by bgedition
View Post
1. MAKE BACKUP of your current .htaccess file
2. find where the request is redirected to https
3. replace that part with the code bellow.
4. save and test

Code:
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/sendemail.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
Nothing happens still redirects me to https.
Reply
#16

It should not be doing that. I tested and confirmed it worked.
Can you please show the contents of the .htaccess.
may be the snippet isn't even executed because its redirected before.
In .htaccess the order matters!
Reply
#17

Quote:
Originally Posted by bgedition
View Post
It should not be doing that. I tested and confirmed it worked.
Can you please show the contents of the .htaccess.
may be the snippet isn't even executed because its redirected before.
In .htaccess the order matters!
Look at my .htaccess now:
PHP Code:
RewriteEngine On 
RewriteCond 
%{SERVER_PORT80 
RewriteCond 
%{REQUEST_URI} !^/sendemail.php
RewriteRule 
^(.*)$ https://%{HTTP_HOST}/$1 [R,L] 
Or wait... this is it .htaccess file unmodified:
PHP Code:
RewriteEngine On 
RewriteCond 
%{HTTP_HOST} ^mydomain\.ro [NC]
RewriteCond %{SERVER_PORT80 
RewriteRule 
^(.*)$ https://mydomain.ro/$1 [R,L]
RewriteRule ^whatsapp"https\:\/\/chat\.whatsapp\.com\/Jsb7br8C8Cw7995AWb5h4z" [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain\.ro$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.ro$
RewriteRule ^sugestii"https\:\/\/www\.forum\.mydomain\.ro\/index\.php\?\/forum\/82\-sugestii\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain\.ro$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.ro$
RewriteRule ^discord"https\:\/\/discord\.gg\/KWWRDZj" [R=301,L
Reply
#18

I presume your web server is hosted. You could ask the support team of the host company. Or may be the .htaccess, that redirects, is located in the directory where public_html is or may be your web server is not Apache but Nginx in which case .htaccess will not work.

Edit: I saw your edit
Change these three lines with the snippet I gave you earlier:
(These are the lines that redirect the whole traffic to https)
Code:
RewriteCond %{HTTP_HOST} ^mydomain\.ro [NC] 
RewriteCond %{SERVER_PORT} 80  
RewriteRule ^(.*)$ https://mydomain.ro/$1 [R,L]
Reply
#19

Quote:
Originally Posted by bgedition
View Post
I presume your web server is hosted. You could ask the support team of the host company. Or may be the .htaccess, that redirects, is located in the directory where public_html is or may be your web server is not Apache but Nginx in which case .htaccess will not work.

Edit: I saw your edit
Change these three lines with the snippet I gave you earlier:
(These are the lines that redirect the whole traffic to https)
Code:
RewriteCond %{HTTP_HOST} ^mydomain\.ro [NC] 
RewriteCond %{SERVER_PORT} 80  
RewriteRule ^(.*)$ https://mydomain.ro/$1 [R,L]
I modify .htaccess file, still redirects me to https
PHP Code:
RewriteEngine On 
RewriteCond 
%{HTTP_HOST} ^mydomain\.ro [NC]
RewriteCond %{SERVER_PORT80 
RewriteCond 
%{REQUEST_URI} !^/sendemail.php 
RewriteRule 
^(.*)$ https://mydomain.ro/$1 [R,L]
RewriteRule ^whatsapp"https\:\/\/chat\.whatsapp\.com\/Jsb7br8C8Cw7995AWb5h4z" [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain\.ro$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.ro$
RewriteRule ^sugestii"https\:\/\/www\.forum\.mydomain\.ro\/index\.php\?\/forum\/82\-sugestii\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain\.ro$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.ro$
RewriteRule ^discord"https\:\/\/discord\.gg\/KWWRDZj" [R=301,L
Reply
#20

Should work. I have tested it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)